i have a timer that is supposed to be synced to all clients, but the problem is that the timer is delayed. It is supposed to go down by 1 every second. but it goes down by 1 like every second and a half or sometimes 2 seconds
Server Script in Serverscriptservice script:
local RS = game:GetService("ReplicatedStorage")
databaseService = require(RS.Infos.DatabaseService)
local globalDatabase = databaseService:GetDatabase("Global")
while wait(0.9) do
local countdown = globalDatabase:GetAsync(500)
if countdown == true then
if game.Workspace.TimerValue.Value == 43 then
local sound = Instance.new("Sound", game.Workspace)
sound.SoundId = "rbxassetid://4577580056"
sound:Play()
end
if game.Workspace.TimerValue.Value == 0 then
game.Workspace.Timer.Value = false
globalDatabase:PostAsync(500, false)
else
game.Workspace.Timer.Value = true
game.Workspace.TimerValue.Value = game.Workspace.TimerValue.Value - 1
end
else
game.Workspace.Timer.Value = false
end
end
Localscript which is inside of a textlabel:
function SecondsToClock(seconds)
local seconds = tonumber(seconds)
if seconds <= 0 then
return "00:00";
else
local hours = string.format(".f", math.floor(seconds/3600));
local mins = string.format(".f", math.floor(seconds/60 - (hours*60)));
local secs = string.format(".f", math.floor(seconds - hours*3600 - mins *60));
return mins..":"..secs
end
end
while true do
wait(0.1)
if game.Workspace.Timer.Value == false then
script.Parent.Parent.Visible = false
else
script.Parent.Parent.Visible = true
script.Parent.Text = SecondsToClock(game.Workspace.TimerValue.Value)
end
end
It may have to do with sloppy code. I use an outside db to store whether the timer has started or not, but the actual countdown is stored inside of the server

1 comment
im not too familiar with time in roblox, but cant you just use unix time? it should stay in sync