Uniform time help

Ayo so I am making a thing where someone can buy a “pro server” where everybody in the server gets x2 Xp blah blah… I have a UI that pops up on everyones screen when a bool value in replicated storage is true. Additioanlly an int value is stored in replicatd storage which holds the “expiration time” (effect only lasts an hour).

So what time is uniform across all client and the server, if such a thing exists, so I can easily display “time left” with just use of current time and when it will expire

I know os.time() won’t work
Will tick() do?

Thanks!

1 Like

There isn’t that I know of, but you could just send the server time to the client via RemoteFunction or RemoteEvent. There’s a slight delay but it seems like it wouldn’t matter in this case. If it does, there are ways to compensate for that too.

@NinjoOnline No need to reply just to say that.

2 Likes

Something like this can be done using tick() on the server side. :slightly_smiling_face:

1 Like

You could do the time remaining calculation on the server, then send the time remaining to every client to display.

1 Like

@Starception Yes, but that seems like such an unnesscary way to go about it. If anything I would just send to the client “hey set an x long timer, k thx” and let the client hanle it from there, and just send it to all joining clients as well. But eh.

@Dev_Ryan Would tick() synch?

1 Like

You should handle the time management on the server only and display time remaining to the clients based on what the server says is remaining. This is the best way to keep timing consistent because calling tick() on the server and client is very likely to bring a different result due to timezones.

Managing time related stuff on the client can easily be abused, for example an exploiter could spoof their timezone and those 24 hour daily rewards that some games do, can easily allow exploiters to get multiple rewards a day if the server doesn’t make these checks.

You don’t need tick() to sync, you need the server to manage it and use the client for the visuals only, because the golden rule is to never trust the client.

1 Like

Well, I am not concerend about security since all this is is a display. If an exploiter would mess with their clock all that would happen would be the UI stays up longer or goes down longer than it should – no actual effect. The actually x2 benefits are handled on the server.

I’m not trusting the client.

1 Like

I would recommend having the server update a NumberValue and have the client use .Changed on that NumberValue to get the time remaining from the server. This value object can be stored in ReplicatedStorage or the Player itself similar to how leaderstats are stored.

1 Like

Ended up just using a number value
;_;

I always feel like that method is inefficient and ugly, but whatta ya’ do.

1 Like

Sending a timer to the client is a much cleaner solution.

Every time you change this number value on the server, the engine has to do a lot more than just that. For the same reason you should only parent new objects after setting the other properties, you shouldn’t use a number value.