Attempt to Index Nil

Hello dev forums, I have been working on a tool but came upon an error.

note: this is a normal script inside of a tool

This is what the output said:

“Players.abrah_m.Backpack.Arrow.Script:5: attempt to index nil with ‘Stand’”

Here is the part of the code where the error occurred:

local player = game.Players:GetPlayerFromCharacter(script.Parent.Parent)

script.Parent.Activated:Connect(function()
’ local char = script.Parent.Parent
’ local stand = player:WaitForChild(“Stand”) ← This is where the output came from

end)

I also have this script in ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
local stand = Instance.new(“StringValue”,player)
stand.Name = “Stand”
stand.Value = “none”
end)

I’m pretty confused on this one as I’m pretty new to tools. Thanks!

Can you please format your code?

When you check the children’s of a player’s inside the Players service, they only contain folders. You probably didn’t index that value in a specific location.

From what I see, it looks like the script is running regardless of whether the tool is in an inventory or not. I believe moving it inside the Activated function should fix it.

1 Like