Accessing StarterGui children

I have TowerDataGui in StarterGui folder that I’m trying to access and enable it through code, I tried first to do this in a module script:

towerDataGui = game.StarterGui.TowerDataGui

This produces no errors but nothing happens on the client’s screen, so I figured I needed to access the gui from the local player so I did this in a module script:

game.Players.PlayerAdded:Connect(function(player)
	towerDataGui = player.PlayerGui:WaitForChild("TowerDataGui")
end)

And in this way a “attempting to index nil with PlayerGui” error popped, what could be the issue?

image
image


image

PlayerAdded is weird on the client - maybe because you are using it on your own client… You could use the PlayerAdded event server-side, and use a RemoteEvent to tell that client to update their Gui.

Not so good method

Edit the player’s PlayerGui server-side.

1 Like

I would suggest using remotes to modify data on the client like the GUI data as it belongs to the client, and thus may not be replicated to the server.

This is just a setup folder for the players. The data you want to work with is in Players. This is where this data is placed for each player.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.