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

i'm trying to make a timer count seconds left in a game?

so i'm trying to make a text label gui count seconds left in a round in a game, but i dont know how to get it to work.

--I use gameTime as the variable for how much time is left, in this case 30 seconds

local gameTime = 30

i don't know if this is even remotely right but i tried doing

local counter = game.StarterGui.top.timeCounter.Text

then referencing it later right after i print this and subtract 1 second each second

print("Game time remaining = "..tostring(gameTime))
      gameTime = gameTime - 1
      if gameTime - 1 then 
counter = gameTime.Value

but i have no ideas

2 comments

0

Line 4 in the last bit of code should be "counter.Text = gameTime.Value"

0

Most of your code is right, but make sure you have a loop. If you need more assistance try watching this video: https://www.youtube.com/watch?v=flRfJBP3kdw

1 answer

✓ Accepted answer

Here try this

Make a StringValue in ReplicatedStorage and name it Status

Make a script in ServerScriptService

And make a localscript inside the textlabel of the countdown

Use this code

Script

local gameTime = 30

local status = game:GetService("ReplicatedStorage"):FindFirstChild("Status")

for  i = gameTime,0,-1 do
	status.Value = "Game in progress: "..i
	wait(1)
end

LocalScript

local status = game:GetService("ReplicatedStorage"):FindFirstChild("Status")

script.Parent.Text = status.Value

status:GetPropertyChangedSignal("Value"):Connect(function()
	script.Parent.Text = status.Value
end)

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