Jump to content

[Help]Syncing player time with server time -- error.


Army@1

Recommended Posts

Hello everyone. I have made a script to synchronize player time with server time but the script is

spamming the debugscript with an error whenever I reconnect the server.

Error: Server triggered clientside event syncTime, but event is not added client side.

It is probably because server script started before client or there are no players in the server.

So far I have tried setting a timer and checking number of players in server but no luck.

Anyone can please help me in this?

Client:-

  
addEvent("syncTime", true) 
addEventHandler("syncTime", getRootElement(), 
    function(h, m) 
        local hc, mc = getTime() 
        if hc ~= h or mc ~= m then 
            setTime(h, m) 
        end 
    end 
) 
  

Server:-

  
setTimer( 
    function() 
        local h, m = getTime() 
        if #getElementsByType("player") >= 1 then 
            triggerClientEvent("syncTime", getRootElement(), h, m) 
        end 
end, 1000, 0) 
  

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...