Help with Ending Round

Hello

I am making a Obby Race game, I want to know how I could end the game if all players have either died or finished the game.

If there are winners then the game would list them and then go back to intermission, same thing when players die but it would just go back to intermission.

I wanted to make a end part, so when the player touches it, it will reload their character and add them to a list of winners.

I don’t know how to do this, I have tried to watch tutorials and took some code from them to see if the code worked, it didn’t.

Here is the script:

-- Variables

local Status = game:GetService("ReplicatedStorage").RoundFolder.Status

local CurrentMap = game.Workspace.CurrentMap
local MusicFolder = game.Workspace.Music

local IntermissionMusic = MusicFolder.Intermission:GetChildren()
local ChoosingMusic = MusicFolder.Choosing
local Countdown = MusicFolder.Countdown

local IntermissionSound = IntermissionMusic[math.random(1, #IntermissionMusic)]

-- Round Settings

local IntermissionTime = 15
local RoundTime = 60
	
	-- Intermission
	
while wait() do
	
	print("Intermission Started!")
	IntermissionSound:Play()
	
		for i = IntermissionTime, 1, -1 do
		Status.Value = "Intermission (" .. i .. ")"
		task.wait(1)
	end
	print("Intermission Ended!")
	IntermissionSound:Stop()
	
	ChoosingMusic:Play()

	Status.Value = "Choosing Map..."
	task.wait(2)
		
	-- Map Selector
		
	local Maps = game:GetService("ServerStorage").Maps:GetChildren()
	local ChosenMap = Maps[math.random(1, #Maps)]:Clone()
		
	ChosenMap.Parent = CurrentMap
	local MapMusic = ChosenMap.MapInfo:FindFirstChild("Sound")
	local MapDifficulty = ChosenMap.MapInfo:FindFirstChild("Difficulty")
	print(ChosenMap.Name .. " (" .. MapDifficulty.Value .. ")")
		
	Status.Value = ChosenMap.Name .. " (" .. MapDifficulty.Value .. ")"
	task.wait(2)
	
	for i = 10, 1, -1 do
		Status.Value = "Teleporting Players in " .. i .. "s"
		wait(1)
	end
	
	-- Teleporting
	
	local MapTeleports = ChosenMap:FindFirstChild("Teleports")
	
	local Players = game.Players:GetChildren()
	for i = 1, #Players do
		if Players[i].Character ~= nil then
			local Teleport = math.random(1, #MapTeleports:GetChildren())
			Players[i].Character:MoveTo(ChosenMap.Teleports:GetChildren()[Teleport].Position)
			Players[i].Character.Parent = workspace.InGame
			Players[i].Character.Humanoid.WalkSpeed = 0
			ChoosingMusic:Stop()
			Countdown:Play()
			
			-- Starting Round
			
			for i = 3, 1, -1 do
				Status.Value = i
				wait(1)
			end
			Status.Value = "GO!"
			task.wait(1)
			Players[i].Character.Humanoid.WalkSpeed = 24
			MapMusic:Play()
			
			-- Round
			
			for i = RoundTime, 1, -1 do
				Status.Value = "Reach the Finish in " .. i .. "s"
				wait(1)
			end
			
			Players[i]:LoadCharacter()
			print("Round Ended!")
			workspace.CurrentMap:ClearAllChildren()
			MapMusic:Stop()
			
		end
	end
end

I want to end the round automatically when all players have died or touched the end part.

I tried multiple times but it wouldn’t work, how can I do this?

1 Like

Uhh u can maybe do tis (there could be an easier way but nto sure)

local totalChars = 0
for i,v in game.Players:GetChildren() do
      if v.Character then
           totalChars +=1
            connection1 = nil
            connection2 = nil
            connection1  = v.CharacterRemoving:Connect(function(c)
                   -- player dead
                       totalChars-=1
                       --check here if the totalCharcount is 0 and then end rou8nd
                       connection2:Disconnect()
                     connection1:Disconnect()
            end)
            connection2  = v.Character["HumanoidRootPart"].Touched:Connect(function(p)
                   if p == FinishlineBox then
                           -- player finished
                       totalChars-=1
                       --check here if the totalCharcount is 0 and then end rou8nd
                        connection1:Disconnect()
                     connection2:Disconnect()
                  end
            end)
      end
end

im not sure if thisll work but its the first thing i came up with :stuck_out_tongue:

2 Likes