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

Why isnt the text changing using this code ??

j = game.StarterGui.ScreenGui.TextLabel
wait(10)
		j.Text = "Game ending in 5"
		wait(1)
		j.Text = "Game ending in 4"
		wait(1)
		j.Text = "Game ending in 3" --  Text to display when the game is about to end
		wait(1)
		j.Text = "Game ending in 2"
		wait(1)
		j.Text = "Game ending in 1"
		wait(1)

4 comments

0

I havea larger script but I downtwant my game idea to be tooken

0

first off, whats triggering this? Somethings gotta trigger the script, it could be a button clicked or other things, second, put local in front of your j, putting local in front of it removes your blue errors.

0

I used math.random to trigger it

0

I am pretty sure math.random isn't a triggering method,

2 answers

StarterGui

You have made the unfortunate mistake of using the StarterGui instead of the PlayerGui. Repeat after me: "I will not change things in StarterGui"
Good boy.

If you need to change something in the StarterGui, you want to instead make sure that you're checking inside the PlayerGui (Which is obviously found in Player.PlayerGui incase you didn't know). Anything found under StarterGui can be found the same way under PlayerGui.


In your case, you unfortunately provide too little context to provide a suitably specific solution to your situation, however you can probably get away with looping through every player:

for k, player in next, game.Players:GetPlayers() do
	-- Do stuff to player.PlayerGui; It'll do it for every player.
end

First of all you'd be better accessing the Players actual GUI, ill explain below.

players = game.Players:GetPlayers() -- Get all the Players in-game
EndingGui = players.StarterGui.ScreenGui.TextLabel -- Get the TextLabel in every players Gui
EndingTime = 5 -- Time left
function EndingTimer()
	for i = EndingTime, 1, -1 do -- Get the time left and take away one
		wait(1) -- Wait one second
		EndingGui.Text = "Game Ending In: " .. i -- The i is the variable storing the time left
	end
	wait(1) -- Wait another second after the timer reaches 0
	EndingGui.Text = "Game Ended" -- Tell the players the game has ended
end
 
EndingTimer()

This was just roughly written there may be mistakes but this is a more efficient way of doing it to what you are.

1 comment

0

Wrong.

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