Hi everyone!
I was making a timer for my game, and realized that when it started, it usually started 3-20 seconds ahead. It didn't get stuck at 0 for a bit then changed to the right time, it just started at that time immediately.
Here is the script that runs the timer:
local isRunning = false
local rs = game:GetService("RunService")
script.Parent.Start.Event:Connect(function() -- this event is running
if isRunning == false then
isRunning = true
local timer = script.Parent
if isRunning == true then
if isRunning == false then print("yes") return end
rs.Stepped:Connect(function(sec, _)
wait()
local truemili = math.floor(sec * 100)/100 - math.floor(sec)
local miliseconds = tonumber(string.sub(truemili, 3, 4))
if miliseconds == nil then miliseconds = 0 end
local minutes = math.floor(sec / 60)
local seconds = math.floor(sec)
if seconds == 60 then
seconds = 0
elseif seconds > 60 then
seconds = seconds - (60*minutes)
end
if miliseconds < 10 then
miliseconds = "0" .. tostring(miliseconds)
end
if seconds < 10 then
seconds = "0" .. tostring(seconds)
end
script.Parent.Text = minutes .. ":" .. seconds .. "." .. miliseconds
script.Parent.Time.Value = minutes .. ":" .. seconds .. "." .. miliseconds
end)
end
end
end)
script.Parent.Stop.OnClientEvent:Connect(function()
isRunning = false
script.Parent.Text = "00:00.00"
script.Parent.Time.Value = "00:00.00"
end)
If anyone could please tell me whats wrong here, id really appreciate it :)
