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

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

Asked by 6 years ago

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

Log in to vote
1
Answered by
noposts 75
6 years ago

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
0
So where do I put the localscript? GIassWindows 141 — 6y
0
anywhere that is a descendant of a playeri.e startergui or starterplayerscripts noposts 75 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

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

0
I did. GIassWindows 141 — 6y
Log in to vote
0
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
6 years ago

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.

Answer this question