Hey there, thanks for coming to check this out.
Anyways, straight to my point. What would be the most efficient way to code a self-updating, daily shop? (Like Fortnite)
What I’m trying to do is a daily shop system (that I’m using a module to get an external time for, so the times should be synced on all servers) to update every 24 hours (I’ve got that figured out already, and I’ve already offset it to 5 PM PST). But, for the items, I’m using a function from a module with weighted randomization, so using a seed wouldn’t generate the same set of items, probably meaning that items across servers would be different.
If you want more info on the function I’m using, it’s a “roll” function I’m using in a module that returns a random rarity. Obviously, I could just make this run in a for loop and then pick random items based on the returned rarity, and boom, that’s how I am planning to get my set of items.
To sync and update, my idea is to use MessagingService; but the problem is that I don’t know how to fully make sure it would only publish the Async once.
Really, in my idea, what I’m trying to do is generate the list of items on one server, and then publish the list to the MessagingService topic and then have servers update on the callback function.
The problem with this is, if there’s no way for me to “debounce” the PublishAsync, wouldn’t the function I’m using that generates items just keep running over and over and republish again until every server has republished their own set of items? (servers would just keep overwriting each other)
The only thing I’ve come up with so far to counter this is to maybe make a bool value in a datastore and then have it act as a debounce. Is this possible?
Basically, I have the daily part figured out. I just need help with the self-updating + server syncing part. How would I debounce a :PublishAsync()?
Also, I want to see if anyone else can come up with another way to do this, so feel free to leave any different ways to do this.
Thanks
EDIT:
I’ve shifted my idea from MessagingService to this:
I could generate a set of items, and then save it to a data store WITH the seed generated for that day. Then, I could add a conditional where it does :GetAsync and then check to see if the seed value in the data store is equal to the seed generated for the current day (which would be the same for every server, as long as its the same day). That way, if the value isn’t the same, it would generate a new set and update the data store with the new seed value. Only thing is wouldn’t all of the servers end up doing :GetAsync at the same time? So, they would all detect an old value because there’s no way for a server to “wait” for another server to update it? Or would it still work because all the servers are still updating the Async regardless?
All I need to know how to do to solve this problem is one of these options:
- Find a way to generate new items with a seed and keep weighted randomization (to keep different rarities)
- Update a data store or a global value somewhere + make sure servers aren’t overwriting each other
Or, any other way someone can offer.
Here’s my code so far for it to update every 24 hours at 5:00 PM PST. I still need to add a seed, of course.