Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

why doesnt this gui work?

	local w = game.StarterGui.gui.timer
	
	script.Parent.Touched:wait()
		w.Visible = true
		repeat
		w.Text = "Game starting in"..game.Lighting.starttime.Value.." seconds"
	wait(1)
	game.Lighting.starttime.Value = game.Lighting.starttime.Value - 1
	until game.Lighting.starttime.Value == 0
	game.Lighting.starttime.Value = 5
	if game.Lighting.starttime.Value == 0 then
	script.Parent:Destroy()
	else print("not yet")
	end

its supposed to display timer, counting down form 5, which is what game.Lighitng.stsrtime.value equals. it doesnt even display the gui when i touch the part the script is in.

1 answer

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");
	-- Stuff
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");
	-- Stuff
end;

Or if you need it all at once,

for _,Player in pairs(game.Players:GetPlayers()) do
	spawn(function()
		local PlayerGui = Player:WaitForChild("PlayerGui");
		-- Stuff
	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

0

i just need to change ots visibility, ive done a script like this but with mousebutton1down. this one just doesnt work

0

That's because on the very first line you set it to a thing in StarterGui, which I totally explained.

This discussion is preserved as it was. New answers, comments, and votes are closed.