Hello again, i’m still making a teleporting system for a client and i noticed that the player after leaving a queue couldn’t join back the same one. How can i fix this?
--
placeId = 5551067564 --Replace with your the game you want to be teleported to
local TeleportSerivce = game:GetService("TeleportService")
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local leaveEvent = ReplicatedStorage.RemoteEvents.LeaveEvent
local joinEvent = ReplicatedStorage.RemoteEvents.JoinEvent
local triggerPart = script.Parent
local teleportNode = script.Parent.Parent:WaitForChild("TeleportNode") -- The part that the players are teleported to
local teleportNode2 = script.Parent.Parent:WaitForChild("TeleportNode2") -- The part that gets the player out
local Folder = triggerPart:WaitForChild("Players")
local timer = script.Parent.Parent.billboardpart.SurfaceGui:WaitForChild("Timer")
local timerTime = 45
local playerCount =script.Parent.Parent.billboardpart.SurfaceGui:WaitForChild("PlayerCount")
local maxPlayers = 2 --This is the max ammount of players
local countDownDebounce = true
local debouncer = false
function checkIfExist(Character)
for _, value in pairs(Folder:GetChildren()) do
if value.Value == Character then
return true
end
end
return false
end
function teleportParty()
local Plrs = {}
for _, value in pairs(Folder:GetChildren()) do
if value.Value then
table.insert(Plrs, Players:GetPlayerFromCharacter(value.Value))
end
end
local ReserveCode = TeleportSerivce:ReserveServer(placeId)
TeleportSerivce:TeleportToPrivateServer(placeId, ReserveCode, Plrs) --Teleports the players in the teleporters
Folder:ClearAllChildren()
end
function countdown()
for i = 1, 45, 1 do
wait(1)
timer.Text = timerTime - i
if timer.Text == "0" then
teleportParty()
print("Teleporting")
wait(5)
countdown()
break
end
end
end
function updateGUI()
playerCount.Text = tostring(#Folder:GetChildren()).."/"..tostring(maxPlayers)
if #Folder:GetChildren() >= maxPlayers or timer.Text == "0" then
teleportParty()
end
end
Players.PlayerAdded:Connect(function()
triggerPart.Touched:Connect(function(hit)
if not debouncer and #Folder:GetChildren() < maxPlayers then
debouncer = true
if hit.Parent:FindFirstChild("Humanoid") and #Folder:GetChildren() < maxPlayers then
print("Player is touching game teleporter")
if not checkIfExist(hit.Parent) then
local Tag = Instance.new("ObjectValue")
Tag.Value = hit.Parent
Tag.Parent = Folder
hit.Parent:SetPrimaryPartCFrame(teleportNode.CFrame)
joinEvent:FireClient(Players:GetPlayerFromCharacter(hit.Parent))
if #Folder:GetChildren() <= maxPlayers then
print("Starting countdown")
countdown()
debouncer = true
end
end
end
debouncer = false
end
end)
end)
leaveEvent.OnServerEvent:Connect(function(player)
for _, value in pairs(Folder:GetChildren()) do
if value.Value == player.Character then
value.Value:Destroy()
player.Character:SetPrimaryPartCFrame(teleportNode2.CFrame)
end
end
end)
Folder.ChildAdded:Connect(updateGUI)
Folder.ChildRemoved:Connect(updateGUI)