Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GUI Timer Countdown?

Asked by 10 years ago
01--List of Map Selections
02local maps = ("DownwardSpiral")
03local boardbasic = game.ServerStorage["HoverBoardBasic"]
04local STGUI = game.StarterGui.SystemGUI.Frame.Label
05--Message and Map Randomizer
06DownwardSpiral = game.Lighting.maps.DownwardSpiral
07--Timer--
08local timer = game.ReplicatedStorage["Time"]
09--Main Game Script--
10while true do
11    STGUI.Text = "Loading..."
12    print("Loaded")
13    wait(5)
14    game.workspace.IntermissionMusic:Play()
15    STGUI.Text = "Intermission-"..timer.Value
16    print("Displayed")
17    wait(60)
18    game.workspace.IntermissionMusic:Stop()
19    end

I'm creating a countdown timer for my game, and I don't want to write 122 lines of useless messaging code. I'm using a StringValue in the ServerScriptStorage and I set it to a number. I'm trying to make it display on the GUI counting down. It displays, but any method I tried didn't make it countdown. Here is my progress system for the game, and I write it as I go. My question is what code should I use to make it count down, and where to put it? Should I put it in a separate script or in the main?

0
Please reformat your code with CodeBlock in order to make it more readable. RedCombee 585 — 10y
0
Just fixed it PhantomR 0 — 10y

2 answers

Log in to vote
2
Answered by
Tkdriverx 514 Moderation Voter
10 years ago

View the hierarchy here. The actual GUI size, color, etc. can be anything you like. Also, the name of the scripts don't matter, so they can be anything you want.

Make sure you have FilteringEnabled set to true.

"ServerScript"

01local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
02local timerActive = false
03 
04-- YOUR CODE HERE (MOST LIKELY RANDOM FUNCTIONS, ETC.) --
05 
06while true do -- Infinite loop
07    -- YOUR CODE HERE (PRE-TIMER) --
08    timerActive = true
09    timeValue.Value = 60 -- The time it starts with.
10 
11    while timerActive do
12        wait(1)
13 
14        timeValue.Value = timeValue.Value - 1
15 
View all 25 lines...

"LocalGui"

01local gui = script.Parent
02local label = gui:WaitForChild("Background"):WaitForChild("TimerLabel")
03local timeValue = game.ReplicatedStorage:WaitForChild("Timer")
04 
05function formatTime(input)
06    local output
07 
08    if type(input) ~= "number" or input < 0 then -- Makes sure it's a number, OR if it's a number and it's a negative number.
09        output = "--:--"
10    else
11        local formatString = "%i:%.2i" -- This is just a formatting string.
12        local seconds = math.floor(input % 60-- input % (modulo) 60 gets the remainder of the division of input and 60. Ex: input = 65; 65 % 60 is 5
13        local minutes = math.floor(input / 60) -- math.floor rounds numbers down towards negative infinity. Just in case input / 60 is a decimal, it becomes a whole number.
14 
15        output = formatString:format(minutes, seconds)
View all 30 lines...

The -- YOUR CODE HERE -- is where your code should go.

I hope this helped. If you have any questions, feel free to contact me or just post a comment on this answer.

I also noticed that you created a table incorrectly on your first line. It should be curly braces ({}), not parenthesis (()).

Ad
Log in to vote
1
Answered by
dyler3 1510 Moderation Voter
10 years ago

You could use this for the countdown. It would show the time remaining(i) until it reaches 0 and would end.

1for i=60,0,-1 do --Sets the timer to 60 seconds, counting down by 1 until it reaches 0
2wait(1)
3STGUI.Text = "Intermission-"..i
4end
0
downvoted xD Konethorix 197 — 5y
0
this works too and is a really short script. ahsan666666666666 264 — 4y

Answer this question