*Sorry for the really long post
-
What do you want to achieve? Keep it simple and clear!
What I want to do is basically what the title says, I am making a 1v1 fighting game where a screen pops up for both players where you choose a character after they’ve been selected for a match from the queue. I want to make it so that, when a player clicks a button, it adds them to a table (the queue), and the server constantly takes two random players in that queue that are close in rank and puts them in a “match” where they can each select a character from gui screens, then afterwards, get teleported to a random map or arena. -
What is the issue? Include screenshots / videos if possible!
The issue is that I’m not sure how to essentially put these two players in a match where only they can see their character selection screens and then teleport these specific players to their arena. I already have scripts made to teleport the players and adjust the cameras as such so there’s no problem with that. But I’m also thinking that I’ll run into the problem of trying to create multiple of these matches with two players at once. I feel like that would get messed up somehow. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
What I have right now is a local script that adds the player to the table(queue) when they click a quickplay button on the screen. And a script in ServerScriptService that loops through the table and gets 2 random players in queue close in rank
This is what my two scripts look like
Local Script:
game.ReplicatedStorage.BindableEvent.Event:Connect(function(queuetable,player1,player2)
local button = script.Parent
local backbutton = script.Parent.Parent.Back
local plr = game:GetService("Players")
local Player = plr.LocalPlayer
--player enters queue
button.MouseButton1Click:Connect(function()
local AlreadyInTable = false
for _,OtherPlayer in next,queuetable do
if OtherPlayer == Player then
AlreadyInTable = true
end
end
if not AlreadyInTable then
table.insert(queuetable,Player)
end
end)
--player leaves queue
backbutton.MouseButton1Click:Connect(function()
table.remove(queuetable,Player)
end)
ServerScript:
local queuetable = {}
game.ReplicatedStorage.BindableEvent:Fire(queuetable)
while #queuetable > 1 do
wait (0.5)
local value1 = math.random(1,#queuetable)
local value2 = math.random(1,#queuetable)
local player1 = table[value1]
local player2 = table[value2]
while value1 == value2 or
player2.leaderstats.mmr.Value < player1.leaderstats.mmr.Value -200 or
player2.leaderstats.mmr.Value > player1.leaderstats.mmr.Value +200 do
wait (1)
value1 = math.random(1,#queuetable)
player1 = table[value1]
value2 = math.random(1,#queuetable)
player2 = table[value2]
end
game.ReplicatedStorage.BindableEvent:Fire(player1, player2)
print("two players have been selected")
end
I’m not sure if the way I’m doing this is the easiest way to accomplish what I’m trying to make or if there’s something I’m doing something wrong entirely but any help is much appreciated and if there is anything else that I need to provide for more support I will gladly post it. I just want some guidance on how I would achieve this in studio because right now I’ve basically hit a brick wall.