I’ve made a party system for my game where i want there to be a customizable amount of people, but for some reason this doesn’t want to work.
Issue - when a player (player1) creates a party and sets it to any number like 2 people, the system wont let (player2) inside of the box after running into the zone which teleports them and it runs the timer and says 1/2 players, but if player1 leaves before the timer is up and goes back in they are able to create another 2 player game which instantly teleports player2 whether touching the hitbox to teleport them in or not and whether its a one player game or not.
Server script.
local TeleportService = game:GetService("TeleportService")
local RS = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local mainGameID = nil
local queueFolder = game.Workspace.Queue
local joinedEvent = RS.JoinedQueue
local leftEvent = RS.LeftQueue
local playerLimit = 4
local countDownTime = 10
for _, queueRoom in ipairs(queueFolder:GetChildren()) do
local enterHitbox = queueRoom.Enter
local exitHitbox = queueRoom.Exit
local tpEnterPos = queueRoom.TpEnterPos
local tpExitPos = queueRoom.TpExitPos
local playersinQueueFolder = queueRoom.PlayersInQueue
local UIBillboard = queueRoom.UI:WaitForChild("UI").BillboardGui
local playersUI = UIBillboard.Players
playersUI.Text = #playersinQueueFolder:GetChildren().. "/" .. playerLimit
local timerUI = UIBillboard.Timer
timerUI.Text = countDownTime .. " Seconds"
local countdownCoroutine
enterHitbox.Touched:Connect(function(other)
print(#playersinQueueFolder:GetChildren())
if #playersinQueueFolder:GetChildren() == 0 and other.Parent:FindFirstChild("Humanoid") then
enterHitbox.CanTouch = false
print("can touch is false")
other.Parent.PrimaryPart.CFrame = tpEnterPos.CFrame
game.ReplicatedStorage.StartGui:FireClient(Players:GetPlayerFromCharacter(other.Parent))
end
local partyGui = game.StarterGui.PartyUi
local background = partyGui.Create.Background
game.ReplicatedStorage.CreatedQueue.OnServerEvent:Connect(function(player, value)
print("can touch is true")
enterHitbox.CanTouch = true
playerLimit = value
print(value, playerLimit)
local db = false
if not (#playersinQueueFolder:GetChildren() >= playerLimit) and not db and other.Parent:FindFirstChild("Humanoid") then
other.Parent.PrimaryPart.CFrame = tpEnterPos.CFrame
if not playersinQueueFolder:FindFirstChild(other.Parent.Name) then
local newPlayer = Instance.new("StringValue", playersinQueueFolder)
newPlayer.Name = other.Parent.Name
newPlayer.Value = other.Parent.Name
end
if countdownCoroutine ~= nil and coroutine.status(countdownCoroutine) == "dead" then
countdownCoroutine = nil
end
if countdownCoroutine == nil then
countdownCoroutine = coroutine.create(function()
CountDownTeleport(playersinQueueFolder, UIBillboard)
end)
coroutine.resume(countdownCoroutine)
end
playersUI.Text = #playersinQueueFolder:GetChildren().. "/" .. playerLimit
local player = Players:GetPlayerFromCharacter(other.Parent)
joinedEvent:FireClient(player, tpExitPos)
task.wait(.1)
db = false
end
end)
end)
exitHitbox.Touched:Connect(function(other)
local db = false
if not db and other.Parent:FindFirstChild("Humanoid") then
db = true
other.Parent.PrimaryPart.CFrame = tpExitPos.CFrame
if playersinQueueFolder:FindFirstChild(other.Parent.Name) then
playersinQueueFolder:FindFirstChild(other.Parent.Name):Destroy()
end
if #playersinQueueFolder:GetChildren() == 0 and countdownCoroutine ~= nil then
coroutine.close(countdownCoroutine)
countdownCoroutine = nil
timerUI.Text = countDownTime .. " Seconds"
end
playersUI.Text = #playersinQueueFolder:GetChildren().. "/" .. playerLimit
local player = Players:GetPlayerFromCharacter(other.Parent)
leftEvent:FireClient(player)
task.wait(.1)
db = false
end
end)
end
function CountDownTeleport(folder, Billboard)
for i = countDownTime, 1, -1 do
Billboard.Timer.Text = i .. " Seconds"
task.wait(1)
end
Billboard.Timer.Text = "Teleporting..."
local party = {}
for _, player in pairs(folder:GetChildren()) do
table.insert(party, Players:FindFirstChild(player.Name))
end
local reservedServer = TeleportService:ReserveServer(mainGameID)
TeleportService:TeleportToPrivateServer(mainGameID, reservedServer, party)
for _, player in pairs(folder:GetChildren()) do
player:Destroy()
end
Billboard.Timer.Text = countDownTime .. " Seconds"
Billboard.Players.Text = "0/"..playerLimit
end
Local Script
local joinedEvent = game.ReplicatedStorage:WaitForChild("JoinedQueue")
local leftEvent = game.ReplicatedStorage:WaitForChild("LeftQueue")
joinedEvent.OnClientEvent:Connect(function(part)
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = part.CFrame
end)
leftEvent.OnClientEvent:Connect(function()
local camera = game.Workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Custom
end)
script.Parent.MouseButton1Click:Connect(function()
local value = script.Parent.Parent.Number.People.Value
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.ExpireBar.Visible = false
print("Clicked locally")
game.ReplicatedStorage.CreatedQueue:FireServer(value)
end)
game.ReplicatedStorage.StartGui.OnClientEvent:Connect(function()
script.Parent.Parent.Visible = true
script.Parent.Parent.Parent.ExpireBar.Visible = true
end)