I wanted to know how to make a part of a script where if all the players died then the round ends and resets the timer back to zero.
Round Code:
function roundCountdown() for roundMinute = 2,0,-1 do for roundSecond = 59,0,-1 do playerNotification('Time left!') playerCountdown(string.format("%d:%.2d",roundMinute,roundSecond)) wait(1) end end end
game.Players.PlayerAdded:connect(function(Player) Player.CharacterAdded:connect(function() local GameValue = Instance.new("BoolValue") GameValue.Parent = Player.Character GameValue.Name = "InGameValue" end) end) --The above adds in the "InGameValue" value every time the player spawns. function CheckPlayers() local InGameNum = 0 --The number of players in game for _,v in pairs(game.Players:GetChildren())do --Scroll through players local Character = v.Character if Character then --Make sure the player's character is not nil local InGameValue = Character:FindFirstChild("InGameValue") if InGameValue and InGameValue == true then --Make sure the player's humanoid is not nil and health is above 0 InGameNum = InGameNum + 1 --Add to the number of players alive else print(Player.."'s InGameValue not found") end else print(Player.."'s Character not found") end end if InGameNum == 0 then --Check to see if everyone is dead return false --Return that everyone is out of the game elseif InGameNum ~= 0 then return true --Return that someone is still in the game else return nil end end function roundCountdown() for roundMinute = 2,0,-1 do for roundSecond = 59,0,-1 do playerNotification('Time left!') playerCountdown(string.format("%d:%.2d",roundMinute,roundSecond)) local CheckInGame = CheckPlayers() if CheckInGame == false then roundSecond = 0 --You may have to "break" after seting it to 0, I'm not sure. elseif CheckInGame == true then print("There are still people in the game") end wait(1) end end end
This code goes after you teleport the players:
--Assuming you already have the player under "game.players". local PlayerInGameValue = player.Character.FindFirstChild("InGameValue") if PlayerInGameValue then PlayerInGameValue.Value = true else print("Can not find: 'InGameValue'") end
This should work, it does require you to set the value of "InGameValue" located in the player's character to true when you place him in a round though.