Reputation: 27
Having problems with one script, I'm getting this error:
Workspace.AgilityZone.HitboxSide.Script:3: attempt to index nil with 'Agility' - Server - Script:3
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player.Agility.Value >= script.Parent.Parent.Requirement.Value then
player.ZoneMulti.Value = script.Parent.Parent.Multi.Value
end
end)
Upvotes: 2
Views: 111
Reputation: 7204
The error is telling you that player
is nil, and that's because game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
isn't guaranteed to return a player. All you need to do is add some safety checks.
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
-- double check that we've got a player
if not player then
return
end
if player.Agility.Value >= script.Parent.Parent.Requirement.Value then
player.ZoneMulti.Value = script.Parent.Parent.Multi.Value
end
end)
Upvotes: 2