StarterGui
StarterGui is cloned and inserted into your PlayerGui when you join, and when you respawn. This means that any changes you do are only seen by the Player after they die and respawn. Inconvenient, huh?
How do I avoid this?
There are a few ways to sort it out, but it all depends on how you're needing it.
When a Player joins
You can get the PlayerGui of a new Player using Players.PlayerAdded
game.Players.PlayerAdded:connect(function(newPlayer)
local newPlayerGui = newPlayer:WaitForChild("PlayerGui");
end);
All players
You can loop through all of the Players in the game and change their PlayerGui together.
for _,Player in pairs(game.Players:GetPlayers()) do
local PlayerGui = Player:WaitForChild("PlayerGui");
end;
Or if you need it all at once,
for _,Player in pairs(game.Players:GetPlayers()) do
spawn(function()
local PlayerGui = Player:WaitForChild("PlayerGui");
end);
end;
A player who did something
You'll need to get your Player from your event first, probably with Players.GetPlayerFromCharacter. After you have your Player, it's just in Player.PlayerGui
A player in a LocalScript
In a LocalScript, you have access to Players.LocalPlayer meaning that your local PlayerGui can be found at game.Players.LocalPlayer:WaitForChild("PlayerGui");
2 comments
i just need to change ots visibility, ive done a script like this but with mousebutton1down. this one just doesnt work
That's because on the very first line you set it to a thing in StarterGui, which I totally explained.