Hello devs,
NOTE: THERE IS AN UPDATED VERSION AVAILABLE - CHECK THE SOLUTION TO VIEW IT
I wanted to share a global matchmaking system that I made, which is WAY simpler than other ones I found. I’m also looking for feedback on it.
This matchmaking system will also include the total players ready.
I have 2 RemoteEvents inside of ReplicatedStorage: “Ready Up” and “Total Players Ready”
This is inside of the ready up button Gui:
-- Note: You can put whatever text and colours you want for the Gui
script.Parent.BackgroundColor = BrickColor.new(0, 200, 0)
script.Parent.Text = "ready up like a pro"
local ready = false
script.Parent.MouseButton1Click:Connect(function()
if ready == false then
script.Parent.BackgroundColor = BrickColor.new(200, 0, 0)
script.Parent.Text = "unready like a noob"
ready = true
game.ReplicatedStorage["Ready Up"]:FireServer(ready)
else
script.Parent.BackgroundColor = BrickColor.new(0, 200, 0)
script.Parent.Text = "ready up like a pro"
ready = false
game.ReplicatedStorage["Ready Up"]:FireServer(ready)
end
end)
This is inside of a ServerScript:
playersReady = {} -- This list will have a list of every player that is ready
shouldReply = true
shouldChange = true
messagingService = game:GetService("MessagingService")
messagingService:SubscribeAsync("Queue", function(msg)
if string.find(tostring(msg.Data), "157981355") then
table.insert(playersReady, string.sub(msg.Data, 1, -10))
elseif string.find(tostring(msg.Data), "058375937") then
table.remove(playersReady, table.find(playersReady, string.sub(msg.Data, 1, -10)))
end
game.ReplicatedStorage["Total Players Ready"]:FireAllClients(playersReady)
end)
messagingService:SubscribeAsync("GetExternalPlayersReady", function()
if shouldReply == true then
shouldChange = false
messagingService:PublishAsync("ExternalPlayersReady", playersReady)
wait()
shouldChange = true
end
end)
messagingService:SubscribeAsync("ExternalPlayersReady", function(msg)
for i in pairs(playersReady) do
table.remove(playersReady[i])
end
for i in pairs(msg.Data) do
table.insert(playersReady, msg.Data[i])
end
end)
game.ReplicatedStorage["Ready Up"].OnServerEvent:Connect(function(playerName, ready)
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. Replace all instances of this number with your replaced one.
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")
end
end)
game.Players.PlayerAdded:Connect(function(playerJoining)
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)
This is inside of a Gui showing the total players ready:
game.ReplicatedStorage["Total Players Ready"].OnClientEvent:Connect(function(playersReady)
if #playersReady == 1 then
script.Parent.Text = #playersReady.. " player is ready"
else
script.Parent.Text = #playersReady.. " players are ready"
end
end)