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

Round-based timer not counting backwards?

I am making a round based sword fighting game, and I am making a timer script with a GUI. My script located in the Workspace simply decrements a variable every second, and sets it to the text of a GUI label. It goes through the loop once, and stops, leaving me with just 29.

Here is the script:

local intermissionTime = 30 -- in secs
local roundTime = 180 -- roundtime in secs
local timerMode = 1 -- 1 means intermission, 2 means round mode

local timerGui = game.StarterGui.timerGUI

while wait(1) do
	-- set timeLabel text to whatever the time left is
	if timerMode == 1 then
		roundTime = 180 -- set roundTime back to 180 since we're
						-- in intermission right now
		intermissionTime = intermissionTime - 1
		timerGui.Frame.timeLabel.Text = (tostring(intermissionTime))
		
		if intermissionTime < 1 then
			timerMode = 2
		end
		
	elseif timerMode == 2 then
		intermissionTime = 30 -- set intermissionTime back to 30
		
		roundTime = roundTime - 1
		timerGui.Frame.timeLabel.Text = tostring(roundTime)
		
		if roundTime < 1 then
			timerMode = 1
		end
		
	end
end



Thanks in advance!

4 comments

0

The issue seems to be that you're using StarterGui instead of the client's PlayerGui. You would need to update the text in each player's UI rather than just StarterGui. I recommend storing some IntValues somewhere and updating the time remaining on each client based on these IntValues, using a localscript.

0

is this a local or server script?

0

this is a server script

0

also, lolzmac, your method did not work, i tired using a localscript and the playergui and it didnt wokr

1 answer

✓ Accepted answer

I think I know your problem: you are using the startergui instead of the players playergui.

The playergui is what the player currently sees and the startergui is what appears when you spawn in/join the game.

To do this you will need to set a variable for the player gui like this:

local player = game.Players.LocalPlayer
local plrGui = player.PlayerGui

Now that we have that we will need to change your code:

local player = game.Players.LocalPlayer
local plrGui = player.PlayerGui
local intermissionTime = 30 -- in secs
local roundTime = 180 -- roundtime in secs
local timerMode = 1 -- 1 means intermission, 2 means round mode

local timerGui = plrGui.timerGUI

while wait(1) do
    -- set timeLabel text to whatever the time left is
    if timerMode == 1 then
        roundTime = 180 -- set roundTime back to 180 since we're
                        -- in intermission right now
        intermissionTime = intermissionTime - 1
        timerGui.Frame.timeLabel.Text = (tostring(intermissionTime))

        if intermissionTime < 1 then
            timerMode = 2
        end

    elseif timerMode == 2 then
        intermissionTime = 30 -- set intermissionTime back to 30

        roundTime = roundTime - 1
        timerGui.Frame.timeLabel.Text = tostring(roundTime)

        if roundTime < 1 then
            timerMode = 1
        end

    end
end

Also you need to use a local script if you are not already.

For additional help, click here.

3 comments

0

I made sure to use the playerGUI, and a localScript, but now, nothing happens, the label text isn't changing at all. I put that exact script in the localScript in workspace, and it isn't working.

0

Nevermind, got it to work by reading the wiki. I put my script into the timerGUI instead of workspace. Thanks for your help!!

0

I added text saying "Round" or "Intermission", and nothing appears, here's the script: https://justpaste.it/381iz

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