How to do something specific but random. The random is updated every 24 hours, like daily rewards

I have an idea to make a server script that would take the local time (the clock on his device taking into account his time zone), compare this time with a pre-selected time point (namely it should be the same time for all - Greenwich - zero meridian). The point is that all players have the same for them for previously generated random actions, which will be equally played with each re-entry into the game, until their local time does not reach the global zeroing of this random, and a new random will not be selected.

To understand this, let me give an example. There is some module-table where there are different rows with different sentences, each unique. Need that during the day (24 hours) was selected once random phrase from there and written to the player’s screen, a new update of this phrase will be exactly in 24 hours, according to global time, namely, when his local time Greenwich reaches 0:00.

I hope that I have explained the essence of the question clearly. Here, a little more of my attempts, how you can realize the idea:

Server script - daily inspiration List of the strings

But I don’t think it should work, and at the very least there would be a big difference among all players. And I want all players to have the same update time for all their entries.

3 Likes

wouldn’t saving the {chosen action/message + the time} in the datastore work?

after this, you can just check if the time passed 24 hours, and if so, pick a new action/message and set the time, then save it again.

3 Likes

its works, actually. but im need to global reset of timer. i mean after 24 hours for all players which time is passed Greenwich 0:00 will be generated new text randomly.

1 Like

ooh, then perhaps you could use os.date(“!*t”)

local date = os.date("!*t") -- this will return a table which has day

if (dayindatastore ~= date["day"]) then
    -- a new day, change dayindatastore to current day
    -- set new message
end
3 Likes

Use date as stated above as a seed for your random number when choosing the daily. So its the same for everyone without saving anything, or manually input days. Could even use a mix of both for special days.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.