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

Players.emay0660.PlayerGui.CollectableUI:9: attempt to index local 'player' (a nil value) ?

Why do i get this error:

Players.emay0660.PlayerGui.CollectableUI:9: attempt to index local 'player' (a nil value)

this script is in my StarterGui folder. Its not local script.

Here my code piece:

local player = game.Players.LocalPlayer
local keyGui = player.PlayerGui:WaitForChild("keyGui")

2 comments

0

"it's not local script" is the reason that player is nil. LocalPlayer is strictly client-only, meaning normal Scripts cannot use it, even if you tried to replicate it to the server. Also, as an additional point, the server cannot access PlayerGui's descendants, but if it were to assign something to PlayerGui, it can access what it put in there.

0

should be a localscript like bash said since normal scripts don't know what the local player is. localscripts should be used for guis / anything you want to show for your player only, not everyone else in the game

1 answer

Is your script a ServerScript or a LocalScript? Your player variable looks perfectly fine. ServerScripts can not access the player through LocalPlayer, only ServerScripts can.

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