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

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

Asked by 3 years ago

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

0
Line 4 in the last bit of code should be "counter.Text = gameTime.Value" appxritixn 2235 — 3y
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 JesseSong 3916 — 3y

1 answer

Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

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)
Ad

Answer this question