I am trying to create a global store system, similar to something like the “Fortnite” item shop… it resets daily and has different cosmetic items etc.
I’ve been able to construct a store that generates different cosmetics to purchase etc, but I haven’t yet been able to set this up to be a daily shop that carries over different servers.
I know that I might be able to use os.time() to do this… but I am not sure exactly how.
Does anyone know how I may achieve this? Do I need to use Datastores?
(I am not that experienced using HTTP service so linking the API page in the replies will do essentially nothing. If you know a solution that uses HTTP, I’d really appreciate an explanation rather than a link <3)
You can use os.time() to check when a day changes, then you can generate a new store whenever the day changes. Getting the store to be the same across all servers will need a seed for your Random instance.
local CurrentDay = os.time() - (os.time() % 84000) -- time in seconds to when the day started
local NextDay
while true do
wait(1)
NextDay = CurrentDay + 84000 -- adds 84000 seconds to the current day
if os.time() > NextDay then -- compares current time to NextDay, if it’s higher then a day has past
-- update store and current day variable here
end
end
Thank you so much! Would something like this work? (I have added an Update function in there)
local CurrentDay = os.time() - (os.time() % 84000) -- time in seconds to when the day started
local NextDay
Update()
while true do
wait(1)
NextDay = CurrentDay + 84000 -- adds 84000 seconds to the current day
if os.time() > NextDay then -- compares current time to NextDay, if it’s higher then a day has past
Update()
end
end
How would a random seed work? Would this be based off the day? Or os.time()
A giant array with a bunch of day numbers may work, but is there a way of randomly generating items to fit a specific number? I haven’t done anything like that before.
BTW, there is already a community tutorial on this, check it out and see if it works. And yeah you can use os.time for this but another method may be to use an external timing system like google which may be more accurate.
It’s supposed to, but it’s not completely synced as I’ve heard, being off from seconds to minutes in between servers. This is why I used a module that fetches time externally to ensure everything is synced. Everything is in the tutorial linked above ^