Hello! If you have played Juke’s Towers of Hell before, you will understand. I’m working on my JToH Fangame and i’m trying to get a timer that goes from 00:00:00, and never ends unless someone touches the winpad (it starts when someone touches a tower portal and gets teleported to the tower)
You already made a similar topic and got plenty of answers
os.clock runs on a persons cpu and will be at different speeds than others.
i would use tick() bec it will be the same everywhere.
but it didnt work out for me. i dont know why tho
why not doing
seconds = 0
minutes = 0
hours = 0
while wait(1) do
seconds += 0
if seconds == 60 then
minutes += 1
seconds =0
end
if minutes == 60 then
minutes = 0
hours += 1
end
game.workspace.timer.Value = hours .. ":" .. minutes .. ":".. seconds
-- this is a stringvalue or somthing
end
and on client u just do
game.workspace.timer.Changed:Connect(function(NewValue)
clientsTextLabel.Text = NewValue
end)
or do u need something more accurate or faster like milliseconds ?
with 00:00:00 i meant
first 00 = minutes
second 00 = seconds
third 00 = milliseconds
You can do for loops and stop the loop when they touch the pad
stays the same change wait(1) to wait(0.1) and rename seconds to milisecond minutes to second and hours to minutes
I recommend you DON’T use wait()
for timers, as they don’t really wait for the exact time you specified. I’d rather use tick()
like how @AC_Starmarine mentioned and use RunService as in how @heII_ish used.
Example code:
local playersService = game:GetService("Players")
local runService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local startBrick = workspace.StartBrick
local finishBrick = workspace.FinishBrick
local timerLabel = script.Parent.Label
local timer = 0
local runConn
startBrick.Touched:Connect(function(hit)
if player ~= playersService:GetPlayerFromCharacter(hit.Parent) then return end
if runConn then return end
local startTime = tick()
runConn = runService.Heartbeat:Connect(function()
timer = tick() - startTime
timerLabel.Text = string.format("%02i:%02i:%02i",
math.floor(timer / 60),
timer % 60,
timer % 1 * 100
)
end)
end)
finishBrick.Touched:Connect(function(hit)
if player ~= playersService:GetPlayerFromCharacter(hit.Parent) then return end
if not runConn then return end
runConn:Disconnect()
runConn = nil
end)
Place file if you want:
Timer.rbxl (31.3 KB)
My explorer:
And finally, the result:
https://vex.is-inside.me/ZXTxKbFl.mp4