So I have a clock that shows the time limit in my gamemode. This clock is part of the HUD and is run completely by the player. However the server does have logic that allows the server to calculate the angle the clock should be in. I got it to work by making that angle a GlobalInt, but it caused some lag that I’d like to try and remove. So I made a timer on the clients side, which gets the timelimit from the server, and calculates the angle itself, until it gets a message from the server that the round has ended. It should theoretically work, but it just doesn’t! I was testing with a time limit set to 1 second, thus making the clocks arrow rotate 1 degree per (1/360) seconds. However it only makes 29 degrees before the time is up! I have no idea why! I also tried making it fire at a fixed 0.01 timer, and then set it to reduce the angle with (360/timelimit)*0.01, but yet this one doesn’t make it past 104 either. They should both theoretically work. Is there just a limit to how fast a clock can run or maybe it’s just not accurate enough?
Here’s some code:
function getRoundRestarted( um ) hasjail = true hassmokespawn = true hassmoke = false Arrowrotation = 0 timelimit = um:ReadFloat() print("Timelimit has been set to "..timelimit) timer.Create("RotationClock", 0.01, 100, function() Arrowrotation = Arrowrotation - ((360/timelimit)*0.01) if Arrowrotation <= -360 then Arrowrotation = 0 end print(Arrowrotation) end) timer.Start("RotationClock") -- The clock above here makes it to 104.4 in one second. end usermessage.Hook("roundrestart", getRoundRestarted) -- The other version of the timer. This one makes it to -29 degrees before 1 seconds has passed. timer.Create("RotationClock", timelimit / 360, 100, function() Arrowrotation = Arrowrotation - 1, function() if Arrowrotation <= -360 then Arrowrotation = 0 end print(Arrowrotation) end)
Is there any way to fix this? Both clocks do not make it far enough and are not synchronized with the server’s time limit. Also, printing “timelimit” does show the correct number, whether it would be 0.002777… or 1 second (depending on if I put ‘/360’ before or after the message was sent).
Image of the console with the second version of the timer used. In this one, instead of “timelimit / 360” it’s just “timelimit” and the ‘/360’ was done before the message was sent to the client.