So I am trying to make a mini game game, however I have no clue on how to add a check to see if all players have died, can someone help me?
So here is the script.
wait(2) local select = script.Rounds:GetChildren() local h = script:WaitForChild("Status") function start() if game.Players.NumPlayers >= 1 then wait(3) wait(1) h.Value = "Choosing gamemode!" local roundchosen = math.random(1, #select) wait(.1) local round = select[roundchosen] print("Chosen round: " .. round.Name) wait(3) if round.Name == "FFA" then FFA() elseif round.Name == "DODGEMS" then DODGEMS() elseif round.Name == "SFFA" then h.Value = "Gamemode chosen: " .. round.Name wait(3) SFFA() end else h.Value = "Waiting for 2 players too start!" wait(1) start() end end function SFFA() local maps = game.Lighting.Maps.FFA:GetChildren() h.Value = "Choosing map.." wait(3) print("Map selection") local mapchosen = math.random(1, #maps) local map = maps[mapchosen] print(map.Name) wait(4) local mapclone = map:Clone() mapclone.Parent = game.Workspace mapclone:MakeJoints() wait(4) for _, player in pairs(game.Players:GetPlayers()) do local contestants = {} table.insert(contestants, player) local spawnmodel = map.Spawns:GetChildren() local spawn = math.random(1, #spawnmodel) local spawnchosen = spawnmodel[spawn] player.Character.Torso.CFrame = CFrame.new(spawnchosen.Position + Vector3.new(0, 3, 0)) spawnchosen:Destroy() end for i = 60, 1, -1 do h.Value = "Time left: " .. i -- The check would go here. wait(1) end start() end
function OnDied() for i,v in pairs(game.Players:GetChildren()) do if v.Character then if v.Character.Humanoid.Health == 0 then print("player had died") end end end end local c = coroutine.resume(coroutine.create(function() OnDied() end))
Add the variable c in the spot you want to check if a player has died, add the function before the main code.