The game is a obby and I would like to add a stopwatch so people could speedrun the obby.
I want to make it so it does not run until you click start and does not stop until you click stop and of course a rest button. COuld someone help me with the script of how this would work?
Is this even possible or no? I think it is I have seen it before.
Solwra
(Solwra)
February 6, 2021, 9:13pm
#3
Here are some resources that are helpful:
tick() returns the local time with milliseconds. In order to turn i.e. 0.312345 into 3, you can simply multiply the number by 10 and use math.floor on it:
local start = tick()
while true do
wait()
local diff = tick() - start
print(diff, "seconds has passed since the start")
local min = math.floor(diff / 60)
local sec = diff - min*60
local mil = math.floor((sec - math.floor(sec)) * 10) -- doing 7.123 - 7 gives us 0.123, then multiply by 10 and floor to get just 1
…
Sounds fun. Here’s a bit of code I typed up that should work.
function Format(Int)
return string.format("%02i", Int)
end
function convertToHMS(Seconds)
local Minutes = (Seconds - Seconds%60)/60
Seconds = Seconds - Minutes*60
local Hours = (Minutes - Minutes%60)/60
Minutes = Minutes - Hours*60
return Format(Hours)..":"..Format(Minutes)..":"..Format(Seconds)
end
Tested examples for proof:
convertToHMS(1) -> “00:00:01”
convertToHMS(59) -> “00:00:59”
convertToHMS(60) -> “00:01:00”
conve…
1 Like