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

Why am I getting the error "attempt to index nil with 'PlayerGui'"?

Asked by 3 years ago

I am currently trying to make a system where every players current cash is shown to every client. I've done this by having a script which gets the Cash value of each player and set a value in Replicated Storage to it. The client then gets this value and sets a text label's text to this value.

However, when I run this, the server script throws this error:

attempt to index nil with 'PlayerGui'

I'm not sure why this is happening as the server can access the playergui from what I know.

The server script:

HttpService = game:GetService("HttpService")
plrsTable = HttpService:JSONDecode(game.ReplicatedStorage.plrs.Value)

while wait() do
    game.ReplicatedStorage.plrData.Cash1.Value = game.Players:FindFirstChild(plrsTable[1]).PlayerGui.Cash.Value
    game.ReplicatedStorage.plrData.Cash2.Value = game.Players:FindFirstChild(plrsTable[2]).PlayerGui.Cash.Value
    game.ReplicatedStorage.plrData.Cash3.Value = game.Players:FindFirstChild(plrsTable[3]).PlayerGui.Cash.Value
    game.ReplicatedStorage.plrData.Cash4.Value = game.Players:FindFirstChild(plrsTable[4]).PlayerGui.Cash.Value
end

(plrsTable is a table of all players in the game)

0
Try to remove :FindFirstChild() and see if it works. Soban06 410 — 3y
0
And do: game.Players[plrsTable[1]].PlayerGui.Cash.Value Soban06 410 — 3y
0
Well thats fixed the original error, but now im getting this one "Cash is not a valid member of PlayerGui" narrowricky -14 — 3y
0
nvm i fixed it by using waitforchild() narrowricky -14 — 3y

Answer this question