Global roster for all servers?

So im making this tower defense game with a random roster every hour. However, different servers will get different rosters because its all random. Is there anyway to make it so every single server gets the same one? Any help is appreciated, thanks!

2 Likes

Have one “main server” (idk how your game works so I would just use the oldest server currently, but really you could use whichever one you want)

use MessagingService | Documentation - Roblox Creator Hub

2 Likes

I’ve never used it before, can it send dictionaries across servers and if so, how?

1 Like

try JSON encoding your dicts and decoding them once you get to the other servers

2 Likes

Truthfully, I have no idea what that means

1 Like

httpservice:JsonEncode(table)
returns a string that can be parsed over through messaging over
httpservice:JsonDecode(string-that-was-json-encoded)
returns a lua table from that string (if valid JSON table)

cause u cant pass tables using messaging service

Yes, you can achieve consistent randomization across different servers in your tower defense game by using a shared seed value for the random number generator. Here’s how you can do it:

  1. Generate a Seed Value: At a specific time (for example, once every hour), generate a seed value that will determine the randomization for that hour. You could use the current time, a hash of the server’s name, or any other unique value as the seed.
  2. Set the Seed for Randomization: Use the generated seed value to set the seed of the random number generator at the beginning of the hour. This will ensure that the sequence of random numbers generated on each server is the same, leading to consistent rosters.
  3. Use the Same Random Sequence: Throughout the hour, use the same sequence of random numbers generated using the set seed. This will ensure that all players on different servers see the same random rosters.

Here’s an example of how you could implement this:

luaCopy code

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Generate a seed value based on the current time
local seed = os.time()

-- Set the seed for the random number generator
math.randomseed(seed)

-- Broadcast the seed to all clients
local remoteEvent = Instance.new("RemoteEvent")
remoteEvent.Name = "SyncRandomSeed"
remoteEvent.Parent = ReplicatedStorage

remoteEvent.OnServerEvent:Connect(function(player)
    remoteEvent:FireClient(player, seed)
end)

In this example, when the hour changes, the server generates a new seed, sets it for the random number generator, and broadcasts it to all clients. Clients then use the received seed to ensure that they use the same random sequence as the server.

Remember that you’ll need to use the same seed throughout the hour for all randomization needs in your game to maintain consistent rosters across different servers.

I’ve never used math.randomseed so I’m not sure how to use it but how could it work with picking the same random tower from each rarity, heres my script:


local function restockRoster()
	for i, rarityTable in pairs(towers) do
		local keys = {}
		for key, _ in pairs(rarityTable) do
			table.insert(keys, key)
		end

		if #keys == 1 then
			local onlyKey = keys[1]
			return rarityTable[onlyKey]
		end

		local position = Random.new():NextInteger(1, #keys)
		local key = keys[position]

		table.insert(towerRoster,rarityTable[key])
		
	end
	print(towerRoster)
end

How could I apply a random seed to this function?