I’ve been trying to make a last player standing round-based system. I don’t want the rounds to go on forever if the players are alive. I already made a basic round system that changes the player’s team depending on if the round starts or ends. I want to use that to end the round when there are 1 player on the ‘Playing’ team. Here is my code, server script, ServerScriptService:
local replicatedStorage = game:GetService("ReplicatedStorage")
local Status = replicatedStorage:WaitForChild("Status")
local InGameBool = replicatedStorage:WaitForChild("InGame")
local MapsFolder = replicatedStorage:WaitForChild("Maps")
local Maps = MapsFolder:GetChildren()
InGameBool.Changed:Connect(function()
if InGameBool.Value == true then
local ChosenMap = Maps[math.random(1,#Maps)]
local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = game.Workspace
wait(2)
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = CFrame.new(ClonedMap.Spawn.Position) -- Teleports
end
else
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
char.HumanoidRootPart.CFrame = CFrame.new(game.Workspace.Lobby.SpawnLocation.Position) -- Teleports
end
for i,v in pairs (MapsFolder:GetChildren()) do
if game.Workspace:FindFirstChild(v.Name) then
local obj = game.Workspace[v.Name]
obj:Destroy()
end
end
end
end)
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
player.Team = game.Teams.Lobby
end)
end)
local function changeTimer()
local players = game:GetService("Players"):GetChildren()
InGameBool.Value = false
for i = 10,0,-1 do
wait(1)
Status.Value = "Intermission:"..i.." Seconds Before New Match!"
if i == 0 then
for i,v in pairs(players) do
v.Team = game.Teams.Playing
end
end
end
InGameBool.Value = true
for i = 10,0,-1 do
wait(1)
Status.Value = "In Game "..i.." Seconds Left Before Game Ends!"
if i == 0 then
for i,v in pairs(players) do
v.Team = game.Teams.Lobby
end
end
end
end
while wait() do
local playersOnTeam = game:GetService("Teams")["Playing"]:GetPlayers()
local numberPlayersOnTeam = #playersOnTeam
if numberPlayersOnTeam < 2 then
changeTimer()
end
end
Feedback is appreciated!