Nope, I made different places for differents level groups.
and then you clicked publish as to fix the problem?
Yeah and for me it worked, I didn’t use TeleportAsync() as well.
Here’s the code:
(It was supposed to be for a comission, that’s why there are many comments)
-- Service variables --
local MemoryStoreService = game:GetService("MemoryStoreService")
local DataStoreService = game:GetService("DataStoreService")
local TeleportService = game:GetService("TeleportService")
-- Datastore variables
local QueueDataStore = DataStoreService:GetDataStore("QueueDataStore")
local queue = MemoryStoreService:GetSortedMap("Queue")
-- Variables --
local remotesFolder = game.ReplicatedStorage:WaitForChild("RemoteEvents")
local queueRemote = remotesFolder.Queue
local teleportingRemote = remotesFolder.Teleporting
-- replace with your places IDs
local zeroTo9 = 13181777762
local tenTo25 = 13226909107
local twentySixTo50 = 13226909257
local fiftyOneTo99 = 13226909425
local hundredTo250 = 13274340960
local twohundred51To500 = 13274342642
local fivehundred1To750 = 13274344189
local sevenhundred51To1000 = 13274346658
-- Table to check if a player is searching or not
local playersInMatchmaking = {}
-- Matchmaking system --
-- Adding and removing player from queue --
queueRemote.OnServerEvent:Connect(function(player, inQueue)
if playersInMatchmaking[player] then return end
playersInMatchmaking[player] = true
if inQueue == "LEAVE" then
pcall(queue:SetAsync(player.UserId, player.UserId, 86400), player)
elseif inQueue == "PLAY" then
pcall(queue:RemoveAsync(player.UserId), player)
end
wait(1)
playersInMatchmaking[player] = false
end)
local function onPlayerLeave(player)
queue:RemoveAsync(player.UserId)
end
game.Players.PlayerRemoving:Connect(onPlayerLeave)
local lastOverMin = tick()
-- Teleporting players to the game --
while wait(1) do
local success, queuedPlayers = pcall(function()
return queue:GetRangeAsync(Enum.SortDirection.Descending, 2)
end)
if success then
local amountQueued = 0
for i, data in pairs(queuedPlayers) do
amountQueued += 1
end
if amountQueued < 1 then
lastOverMin = tick()
end
local timeInQueue = tick() - lastOverMin
if amountQueued == 2 then
for i, data in pairs(queuedPlayers) do
local userId = data.value
local player = game.Players:GetPlayerByUserId(userId)
if player then
local levels = player.PlayerStats.Levels
if levels.Value >= 1 or levels.Value <= 9 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(zeroTo9)
TeleportService:TeleportToPrivateServer(zeroTo9, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 10 or levels.Value <= 25 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(tenTo25)
TeleportService:TeleportToPrivateServer(tenTo25, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 26 or levels.Value <= 50 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(twentySixTo50)
TeleportService:TeleportToPrivateServer(twentySixTo50, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 51 or levels.Value <= 99 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(fiftyOneTo99)
TeleportService:TeleportToPrivateServer(fiftyOneTo99, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 100 or levels.Value <= 250 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(hundredTo250)
TeleportService:TeleportToPrivateServer(hundredTo250, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 251 or levels.Value <= 500 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(twohundred51To500)
TeleportService:TeleportToPrivateServer(twohundred51To500, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 501 or levels.Value <= 750 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(fivehundred1To750)
TeleportService:TeleportToPrivateServer(fivehundred1To750, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
elseif levels.Value >= 751 or levels.Value <= 1000 then
local success, err = pcall(function()
local ServerId = TeleportService:ReserveServer(sevenhundred51To1000)
TeleportService:TeleportToPrivateServer(sevenhundred51To1000, ServerId, {playersInMatchmaking})
teleportingRemote:FireClient(player)
end)
end
spawn(function()
if success then
wait(1)
pcall(function()
queue:RemoveAsync(data.key)
end)
end
end)
end
end
end
end
end
Ty alot I published the places and it worked.
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.