Saving weather across all servers

I need to sync the weathers on each island individually across all servers. Some Islands could be snowing, or raining, or just normal. How can I achieve this?

I’ve tried using MessagingService, but when a new server starts up I don’t know how to get the information that I’ve been transferring to each server.

You could use datastores and messaging service together.

One server could save to the datastore.

A better way to do this would be to store it on some alternative api.

This doesn’t sound like a bad idea. I just don’t know if it will work 100%, because what if all servers fire PublishAsync at once, and the datastore saves them all? Some servers may be different than other ones in that case.

You’re right.

An alternative api would definitly be the best way to do this. But in my opinion it’s better to just use os.time() and math.randomseed()

I will make a code example and send it to you in a minute.

2 Likes

As @RayK_iv said,

you can use local ChronoRandom = Random.new(os.time()) and Chronorandom:NextNumber(1, 2).

To get the same weather across all servers you need to use os.time().

local currentWeather = "Clear"

local weatherTimes = {
Rain = 200,
Snow = 600,
Clear = 900,
}
local maxTime = 1400

while true do
local currentTime = os.time()%maxTime
local bestMatch
for weather, t in pairs(weatherTimes) do
if t > currentTime then
bestTime = t
bestMatch = weather
end
currentWeather = bestMatch or 'not work'
print("It's "..currentWeather.."ing!")
task.wait(300) --5 minutes
end