Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I keep getting attempt to index local 'User' (a nil value). How do I fix it?

So I made a short script so you get a certain GUI when you join the game. But I get this error.

12:26:04.771 - Workspace.HandToHandle:4: attempt to index local 'User' (a nil value)

12:26:04.772 - Stack Begin

12:26:04.772 - Script 'Workspace.HandToHandle', Line 4

12:26:04.773 - Stack End

And my script is:

game.Players.PlayerAdded:Connect(function(plr)
local Players = game:GetService("Players")
local User = Players:FindFirstChild(plr)
local UserGUI = User:FindFirstChild("PlayerGui")
local Handto = script.Handtoui:Clone(UserGUI)
end)

No errors in the script so I don't know what I did wrong here.

2 answers

✓ Accepted answer

FindFirstChild() only takes strings as arguments. Therefore, on line 3, change local User = Players:FindFirstChild(plr) to local User = Players:FindFirstChild(plr.Name).

1 comment

0

Thank you!

plr is already defined as the local player so therefore u dont need to access the players again, u can just do this

local User = plr

This discussion is preserved as it was. New answers, comments, and votes are closed.