Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Lualaxy 78
5 years ago

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

Log in to vote
0
Answered by
Drainhp 41
5 years ago

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

0
Thank you! Lualaxy 78 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

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

Answer this question