Hello all(First Post), I'm currently making a simple game that has Matchmaking system with MMR. I've currently run into this problem of where everything works, but trying to teleport players that have been matched with each other doesn't work. What can I do to call the Players that are in the table, to be teleported? [Line 95]
--Locals
local TeleportService = game:GetService("TeleportService")
local PrimaryMap = script.Parent.Primary.Value
local Place = PrimaryMap --Number Value for the current place ID rotation
MMRData = game:GetService("DataStoreService"):GetDataStore("MMR")
UpdateRate = 3 --Rate at which the Queue is updated
debugmode = true
local ModuleScript = script:WaitForChild("ModuleScript")
local _M = require(ModuleScript) --Req'd
function debugPrint(msg) --Helping with bugs (EH)
if debugmode then
print("DB= "..msg)
end
end
function game.ReplicatedStorage.ReqInfo.OnServerInvoke(player)
--Giving the Primary
local PrimaryMap = script.Parent.Primary.Value
return PrimaryMap
end
local PlayersInQueue = {}
local JoinQueueQueue = {}
--Default Player Data
function game.ReplicatedStorage.JoinQueue.OnServerInvoke(Player)
local PlayerData =
{
PlayerName = "";
MMR = 0;
Range = 50;
Matched = false; --Setting to false so player doesn't get Matched when joining
}
PlayerData["MMR"] = 0--MMRData:GetAsync(tostring(Player.userId))
PlayerData["PlayerName"] = Player.Name
table.insert(JoinQueueQueue,1,PlayerData)
return true
end
local Matches = {}
while true do
print("Matchmaking tick"..UpdateRate)
local function CreateMatch(FirstPlayer)
print("Creating New Match")
local NewMatch = {}
NewMatch["Average"] = FirstPlayer["MMR"]
debugPrint("Average set for new match = "..tostring(FirstPlayer["MMR"]))
NewMatch["Range"] = 50
FirstPlayer["Matched"] = true
table.insert(NewMatch,1,FirstPlayer)
table.insert(Matches,1,NewMatch)
end
wait(UpdateRate)
print("Players in JoinQueueQueue = "..#JoinQueueQueue)
if #JoinQueueQueue > 0 then
for i=1, #JoinQueueQueue do
print("Transfered "..JoinQueueQueue[i]["PlayerName"].."into the player Queue")
print("Index = "..tostring(i))
table.insert(PlayersInQueue,1,JoinQueueQueue[i])
JoinQueueQueue[i] = nil
end
end
print("PlayersInQueue = "..#PlayersInQueue)
if #PlayersInQueue > 0 then
for i=1, #PlayersInQueue do
debugPrint("Scanning players "..PlayersInQueue[i]["PlayerName"])
if PlayersInQueue[i]["Matched"] == false then
debugPrint("Matched = true")
if #Matches~= 0 then
print("Matches~= 0")
for i_2=1,#Matches do
print("Matches ~= 0 =")
local Diff = Matches[i_2]["Average"] - PlayersInQueue[i]["MMR"]
if Diff < 0 then
Diff = Diff * -1
end
if Matches[i_2]["Range"] >= Diff then
--Should be In Range of Match
print("Player is in range of the match")
table.insert(Matches[i_2],1,PlayersInQueue[i])
break
end
end
else
print("No matches exist, let's make one!")
CreateMatch(PlayersInQueue[i])
end
end
end
end
print("Amount of Matches = "..#Matches)
if #Matches > 0 then
for i=1, #Matches do
Matches[i]["Range"] = Matches[i]["Range"] + 2
if #Matches[i] == 10 then
print("Match Made! TP time bois")
TeleportService:Teleport(Place, )--Current Issue of how to call the players Matched
end
end
end
end
