playersReady = {} -- This list will have a list of every player that is ready
shouldReply = true -- Whether this server will tell a new server how many players are ready or not
shouldChange = true -- Whether this server will change based on the other servers sending back how many players are ready or not
messagingService = game:GetService("MessagingService")
messagingService:SubscribeAsync("Queue", function(msg) -- This subscribes to the sub-category of messaging service (the queue)
if string.find(tostring(msg.Data), "157981355") then -- This finds the number telling the server if the player is ready or unready; in this case, "157981355" means ready
table.insert(playersReady, string.sub(msg.Data, 1, -10)) -- Removes the number telling the server to ready or unready the player, then adds it to the playersReady list
elseif string.find(tostring(msg.Data), "058375937") then -- This finds the number telling the server if the player is ready or unready; in this case, "058375937" means unready
table.remove(playersReady, table.find(playersReady, string.sub(msg.Data, 1, -10))) -- Removes the number telling the server to ready or unready the player, then adds it to the playersReady list
end
game.ReplicatedStorage["Total Players Ready"]:FireAllClients(playersReady) -- Tells our last script how many players are ready
end)
messagingService:SubscribeAsync("GetExternalPlayersReady", function() -- Servers that already exist are told to send the number of players ready with this function
if shouldReply == true then
shouldChange = false
messagingService:PublishAsync("ExternalPlayersReady", playersReady) -- Tells our brand new server how many players are ready
wait()
shouldChange = true
end
end)
messagingService:SubscribeAsync("ExternalPlayersReady", function(msg) -- The new server will use this to get how many players are ready in an external server
for i in pairs(playersReady) do
table.remove(playersReady[i]) -- Clears the current playersReady table
end
for i in pairs(msg.Data) do
table.insert(playersReady, msg.Data[i]) -- Adds the players ready in another server the this server's playersReady table
end
end)
game.ReplicatedStorage["Ready Up"].OnServerEvent:Connect(function(playerName, ready) -- Detects when a player readied or unreadied
game.ReplicatedStorage["Ready Up"]:FireClient(playerName, ready)
if ready == true then
messagingService:PublishAsync("Queue", tostring(playerName).."157981355") -- This can be a number or code of any length, but make it something that no one has in their username.
else
messagingService:PublishAsync("Queue", tostring(playerName).."058375937") -- Same with this code.
end
end)
game.Players.PlayerRemoving:Connect(function(playerLeaving)
if table.find(playersReady, tostring(playerLeaving)) then
messagingService:PublishAsync("Queue", tostring(playerLeaving).."058375937") -- Removes the player that left's name from the playersReady table; if it's on there
end
end)
game.Players.PlayerAdded:Connect(function(playerJoining) -- Detects if this is a new server, if so, it will get the list of players that are ready from another server
if #game.Players:GetPlayers() == 1 then
shouldReply = false
messagingService:PublishAsync("GetExternalPlayersReady", "")
wait()
shouldReply = true
else
game.ReplicatedStorage["Total Players Ready"]:FireClient(playerJoining ,playersReady)
end
end)
In this code, how can I make every queued player get teleported to a reservedserver?