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

"a nil value" keeps popping up, how do I fix this?

It says:

ServerScriptService.Script:5: attempt to index field 'PlayerGui' (a nil value)

Here's the part of the script:

players = game.Players:GetChildren()
local textLabel = players.PlayerGui.ScreenGui.TextLabel

Is there something I'm doing wrong?

3 answers

✓ Accepted answer

I assume you're using a server sided script because that error came from server script service.

You cannot access the PlayerGui of a player using a server script. What you should do instead is put that in a local script and tweak it a little. You also tried to get PlayerGui from a table named "players" which is a common mistake because :GetChildren() is often misunderstood

local player = game:GetService("Players").LocalPlayer -- gets the player
local textLabel = player:WaitForChild("ScreenGui"):WaitForChild("TextLabel") -- waits for the text label and returns it to textLabel, used :WaitForChild() incase they load late

2 comments

0

So where do I put the localscript?

0

anywhere that is a descendant of a playeri.e startergui or starterplayerscripts

Dude, take a 'ScreenGui' ; put that to 'StarterGui' and insert the things you wish into the ScreenGui. That's all !

1 comment

0

I did.

You can access a player's PlayerGui's descendants when FE is disabled, but can't access them when FE is enabled.

Use a client - sided script, a.k.a LocalScript.

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