So i’ve lately been trying to make a last-man-standing game which teleports everyone to a arena. The round ends when everyone but one person is killed. The problem is I cannot tell when there is only 1 person left. I need help with creating a script that fires a function when there’s only 1 person left.
Here’s what i’ve tried so far ( I planned to make it check every second if someones in a team )
Code that doesn't work
repeat
wait(1)
for i, player in pairs(game.Teams.Fighting:GetPlayers()) do
if player == nil then -- Checks if there's no one on the team
script.Value.Value = false
end
end
until script.Value.Value == false
The problem with that is that the round script is a while true do loop. How would I do that in a while true loop without it repeatedly doing Humanoid.Died?
Entire round code
local Players = game.Players
while true do
wait(30)
-- intermsiion--
script.IntermisionTime.Value = 15
repeat
wait(1)
script.IntermisionTime.Value = script.IntermisionTime.Value - 1
for i, player in pairs(Players:GetPlayers()) do
player.PlayerGui.MainGui.MainTextLabel.Text = script.IntermisionTime.Value
end
until script.IntermisionTime.Value < 1
-- -- -- -- --
-- teleports playeres into arena-
for i, player in pairs(Players:GetPlayers()) do
local Spawn = script:FindFirstChild("Spawn".. math.random(1,10))
player.Character.HumanoidRootPart.Position = Vector3.new(Spawn.Position.X, Spawn.Position.Y, Spawn.Position.Z)
player.Team = game.Teams.Fighting
end
----
-- checks if team is empty--
script.Value.Value = true
repeat
wait(1)
for i, player in pairs(game.Teams.Fighting:GetPlayers()) do
if player == nil then
script.Value.Value = false
end
end
until script.Value.Value == false
---------------------------
print("hi") -- just a print
end
Thank you for the help! ( Sorry if the script is messy )
When the round starts, make a table and add all the players to the table. Then use Humanoid.Died to check when a player has died. Once they have died, remove them from the table. Then check once there is only 1 player in the table and end the round.