Problem with ending round

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to solve the problem with the ending round
  2. What is the issue? Include screenshots / videos if possible!
    The issue is when 1 player dead and second is live, and at the ending round writes, that 2 players survived
    Here is my script
local Maps = game.ReplicatedStorage.Maps:GetChildren()
local Status = game.ReplicatedStorage.Status


local function arePlayersAlive()
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Character = Player.Character
		if Character then
			local Humanoid = Character:FindFirstChildOfClass("Humanoid")
			if Humanoid and Humanoid.Health > 0 then
				return true 
			end
		end
	end
	return false 
end


local function getSurvivingPlayers()
	local survivingPlayers = {}
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Character = Player.Character
		if Character then
			local Humanoid = Character:FindFirstChildOfClass("Humanoid")
			if Humanoid and Humanoid.Health > 0 then
				table.insert(survivingPlayers, Player.Name)
			end
		end
	end
	return survivingPlayers
end


while true do
	
	wait(.1)
	for i = 20, 0, -1 do
		Status.Value = "Intermission: " .. i
		task.wait(1)
	end

	
	local ChosenMap = Maps[math.random(1, #Maps)]
	local ClonedMap = ChosenMap:Clone()
	ClonedMap.Parent = game.Workspace
	Status.Value = "Map: " .. ClonedMap.Name

	task.wait(3)

	
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Character = Player.Character
		if Character then
			local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
			if HumanoidRootPart then
				HumanoidRootPart.CFrame = ClonedMap.TeleportPoint.CFrame
			end
		end
	end

	
	local gameOver = false
	for i = 10, 0, -1 do
		Status.Value = "Game: " .. i
		task.wait(1)

		
		if not arePlayersAlive() then
			Status.Value = "No one survived!"
			task.wait(1)
			gameOver = true
			break
		end
	end

	
	if not gameOver then
		local survivingPlayers = getSurvivingPlayers()
		if #survivingPlayers > 0 then
			Status.Value = "Surviving players: " .. table.concat(survivingPlayers, ", ")
		else
			Status.Value = "No one survived!"
		end
	end
	task.wait(2)

	
	for _, Player in pairs(game.Players:GetPlayers()) do
		local Character = Player.Character
		if Character then
			local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
			if HumanoidRootPart then
				HumanoidRootPart.CFrame = Lobby.TeleportPoint.CFrame
			end
		end
	end

	
	ClonedMap:Destroy()
end

The problem with the function that gets the surviving players is that it gets any players that respawn after meaning they have a hp above 0. Having health above 0 means they’ll get added anyway. This depends if the characters auto respawn or not which i cant tell. If they do auto respawn… Add a tag to the players that get into the match like “InMatch” and when they die you’ll remove this tag. After the round ends, check for the players with this tag and it should get the players remaining

1 Like

could you write a proper script that will work please?

Nevermind, I fixed it, thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.