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)

4 comments

0

Try to remove :FindFirstChild() and see if it works.

0

And do: game.Players[plrsTable[1]].PlayerGui.Cash.Value

0

Well thats fixed the original error, but now im getting this one "Cash is not a valid member of PlayerGui"

0

nvm i fixed it by using waitforchild()