Hello to all in Dev Forum,
I am trying to create a banner system similar to all star tower defence. How do they make the banner change every hour and for every single server to the exact same units on the banner?
I’ve tried looking for solutions on Developer Hub but I couldn’t find any, I attempted using data stores but I had no idea how to achieve what All Star Tower Defence has.
If anyone could help and assist me in creating the script, that would be great (im not asking for full scripts)
I think there’s a script in every server that cjhecks the current hour of the server and. Then base off of it do what is supposed to, I don’t know how to do that sorry
well, i do know how to create a system that checks for every hour that passes within a server. But that is limited to only a single server, so if a new server opens the time would start over and I do no want that.
What you could do is create a random seed using the current hour. For example, this: math.floor((tick())/3600) increments by one every hour. Using it, you could try this:
local seed = math.floor((tick())/3600)
local RNG = Random.new(seed)
-- The things generated by the Random object will be different every hour,
-- but will be EXACTLY the same for each server
It is worth noting that this will not update every hour, so servers would likely need to keep track of when the hour turns over and update it accordingly. You can get the seconds until the next hour with this: 3600 - (tick() % 3600)
I have one more question, how would I use the RNG to generate new banners? When I try to print the RNG, it returns me “Random”. I’m not sure what I can do with that. Could I have a brief explanation on what I can do with it? Sorry, I am fairly new to using Random.new()
Random is an object that is used to create random numbers. Instead of being a random number, it’s an object that creates random numbers. Here’s some example usage:
local RNG = Random.new(tick())
local int = RNG:NextInteger(3,10) -- Example return: 6
local randomPercent = RNG:NextNumber() -- Example return: 0.7328936445
local randomNum = RNG:NextNumber(20,50) -- Example return: 43.773829543
local randomVect = RNG:NextUnitVector() -- Example return: -0.14028, 0.50161, 0.8536405
Also yes, because it’ll be the same generated items in each server, they’ll remain in sync as long as you update it every hour and make sure to push updates to the generation in one wave.