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

How can this tick clock work?

Asked by 8 years ago

Hi,

I was wondering how to make a tick clock because I want to count time locally not based on server lag or anything. I don't know how to count in tick so basically I want to make a stopwatch which ends at the players death and starts basically at the time I want it to. I also want the time to go onto a gui and be in a colon format like (3(m):05(s):04(ms).

Would it look something like this? (This wont work)

local startTime = tick()

while wait(1) do -- This wont work because there is still a wait inside which doesnt count globally.
currentTimeAmount = tick()
textLabel.Text = currentTimeAmount -- I know this is wrong because i didnt declare a variable but i need -- to be quick
end

-- I'm stuck on rounding and formatting the timer in the way I want it to be.
-- I'm also stuck on stopping at death but I know the event to use is humanoid.Died.

Thanks

0
The wait() delta is useful. User#6546 35 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

You can try something like this

local i = 0;
local unbreak = true;
yourPlayer.Humanoid.Died:connect(function()
    unbreak = false;
end);
while unbreak do
    i = i+wait(1);
    timer.Text = string.format("%.1d:%.2d:%.2d", i/3600, (i/60)%60, i%60);
end;

You'll need to declare timer and yourPlayer, and you'll need to make this code run when you need it to.

0
Doesn't this use wait? Thanks but I want a stopwatch that isn't effected by lag at all, I want something that LifeInDevelopment 364 — 8y
0
It won't. I've made it use the delta - The most lag you're going to get from it is miliseconds worth of lag from the format function accumulating over minutes or hours of running. User#6546 35 — 8y
Ad

Answer this question