How to detect players in round?

Hi, I need help. I’m currently working on a roundSystem and I have a problem, how can I detect players in the round ?

Here is the script :

local RoundLength = 20
local IntermissionLength = 10

local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status

local LobbySpawn = game.Workspace["Lobby map"].SpawnLocation
local GameSpawn = game.Workspace.GameTPPart

local SpleefParts = game.ServerStorage.SpleefParts

InRound.Changed:Connect(function()
	wait(1)
	if InRound.Value == true then
		for _, player in pairs(game.Players:GetChildren()) do
			SpleefParts:Clone().Parent = workspace
			wait(0.5)
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameSpawn.CFrame
		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			game.Workspace.SpleefParts:Destroy()
		end
	end
end)

local function roundFunction()
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Game starts in " .. i
		end

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
	end
end

spawn(roundFunction)

Thanks and have a nice day

1 Like

You could try storing the players inside a table:

local plrs = {}
local RoundLength = 20
local IntermissionLength = 10

local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status

local LobbySpawn = game.Workspace["Lobby map"].SpawnLocation
local GameSpawn = game.Workspace.GameTPPart

local SpleefParts = game.ServerStorage.SpleefParts

InRound.Changed:Connect(function()

	wait(1)
	if InRound.Value == true then
     
		for _, player in ipairs(game.Players:GetChildren()) do
			SpleefParts:Clone().Parent = workspace
			wait(0.5)
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameSpawn.CFrame
           table.insert(plrs, player)
		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			game.Workspace.SpleefParts:Destroy()
		end
	end
end)

local function roundFunction()
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Game starts in " .. i
		end

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
	end
end

spawn(roundFunction)

Thanks, I will try that in the game. Because I will make an if() to see if there is only one player in the round.

And also don’t forget to clear it when the round ends.

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
            table.clear(plrs)
	end
end

spawn(roundFunction)

Thanks RaxelRbx ! I almost forget :sweat:. Now my system works correctly.

But I got a problem, when two players are joining, it reset the round or, when a player die the round is not stopped : /

Here is the new script :

local RoundLength = 20
local IntermissionLength = 10

local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status

local LobbySpawn = game.Workspace["Lobby map"].SpawnLocation
local GameSpawn = game.Workspace.GameTPPart

local SpleefParts = game.ServerStorage.SpleefParts

local plrs = {}

InRound.Changed:Connect(function()

	wait(1)
	if InRound.Value == true then

		for _, player in pairs(game.Players:GetChildren()) do
			SpleefParts:Clone().Parent = workspace
			wait(1)
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameSpawn.CFrame
			table.insert(plrs, player)
			if #plrs == 1 then
				Status.Value = "Winner: " .. player.Name
				InRound.Value = false
			end

		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			game.Workspace.SpleefParts:Destroy()
		end
	end
end)

local function roundFunction()
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Game starts in " .. i
		end

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			if not InRound.Value then break end
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
		table.clear(plrs)
	end
end

spawn(roundFunction)

Is your Script a LocalScript or a ServerScript?

It is a server script in ServerScriptService.

Try this:

local RoundLength = 20
local IntermissionLength = 10

local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status

local LobbySpawn = game.Workspace["Lobby map"].SpawnLocation
local GameSpawn = game.Workspace.GameTPPart

local SpleefParts = game.ServerStorage.SpleefParts

local plrs = {}

InRound.Changed:Connect(function()

	wait(1)
	if InRound.Value == true then

		for _, player in pairs(game.Players:GetChildren()) do
			SpleefParts:Clone().Parent = workspace
			wait(1)
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameSpawn.CFrame
			table.insert(plrs, player)
			if #plrs == 1 then
				Status.Value = "Winner: " .. player.Name
				InRound.Value = false
			end

		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			game.Workspace.SpleefParts:Destroy()
		end
	end
end)

local function roundFunction()
for i,plr in plrs do 
plr.Character.Humanoid.Died:Connect(function()
table.remove(plrs, plr)
end)
end
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Game starts in " .. i
		end

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			if not InRound.Value then break end
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
		table.clear(plrs)
	end
if #plrs = 1 then
break
end

spawn(roundFunction)

Sorry but it doesn’t work too, 1 out of 2 times, the game restarts automatically, and then when it works, even if a player falls and only one is left, the game continues until it reaches 0, and then it starts all over again.

Try the updated script above. I edited it.

1 Like

Whoop, it is more broken. Even the GUI is broke :sweat_smile:. I’m desperate lol

What do you mean, which GUI are you talking about?

I have a GUI in my game but that’s ok for that. It is just the main script that is broken.

Try this there were some errors:

local RoundLength = 20
local IntermissionLength = 10

local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status

local LobbySpawn = game.Workspace["Lobby map"].SpawnLocation
local GameSpawn = game.Workspace.GameTPPart

local SpleefParts = game.ServerStorage.SpleefParts

local plrs = {}

InRound.Changed:Connect(function()

	wait(1)
	if InRound.Value == true then

		for _, player in pairs(game.Players:GetChildren()) do
			SpleefParts:Clone().Parent = workspace
			wait(1)
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameSpawn.CFrame
			table.insert(plrs, player)
			if #plrs == 1 then
				Status.Value = "Winner: " .. player.Name
				InRound.Value = false
			end

		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			game.Workspace.SpleefParts:Destroy()
		end
	end
end)

local function roundFunction()
for i,plr in plrs do 
plr.Character.Humanoid.Died:Connect(function()
table.remove(plrs, plr)
end)
end
	while wait() do
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Game starts in " .. i
		end

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			if not InRound.Value then break end
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
		table.clear(plrs)
	end
if #plrs == 1 then
		return
			end
end

spawn(roundFunction)

Well, it is the same thing. 1 out of 2 times, the game restarts automatically, and then when it works, even if a player falls and only one is left, the game continues until it reaches 0…

I tried myself to see what’s was wrong but idk… something seems broken

Ok wait I found the issue. One moment.

Try this:


local RoundLength = 20
local IntermissionLength = 10

local InRound = game.ReplicatedStorage.Values.InRound
local Status = game.ReplicatedStorage.Values.Status

local LobbySpawn = game.Workspace["Lobby map"].SpawnLocation
local GameSpawn = game.Workspace.GameTPPart

local SpleefParts = game.ServerStorage.SpleefParts

local plrs = {}

InRound.Changed:Connect(function()

	wait(1)
	if InRound.Value == true then

		for _, player in pairs(game.Players:GetChildren()) do
			SpleefParts:Clone().Parent = workspace
			wait(1)
			local char = player.Character
			char.HumanoidRootPart.CFrame = GameSpawn.CFrame
			table.insert(plrs, player)


		end
	else
		for _, player in pairs(game.Players:GetChildren()) do
			local char = player.Character
			char.HumanoidRootPart.CFrame = LobbySpawn.CFrame
			game.Workspace.SpleefParts:Destroy()
		end
	end
end)

local function roundFunction()
	for i,plr in plrs do 
		plr.Character.Humanoid.Died:Connect(function()
			table.remove(plrs, plr)
		end)
	end
	while wait() do
		if InRound.Value == true then
		
		for i = IntermissionLength, 1, -1 do
			InRound.Value = false
			wait(1)
			Status.Value = "Game starts in " .. i
		end

		InRound.Value = true
		for i = RoundLength, 1, -1 do
			if not InRound.Value then break end
			wait(1)
			Status.Value = "Game ends in " .. i
		end
		InRound.Value = false
		table.clear(plrs)
		if #plrs == 1 then
            
			InRound.Value = false
			
			end
		else
			break
			
			
	end
	end
end
		

spawn(roundFunction)

Ok so, I’ve tested it and now, it seems that there is a problem with the status value. Because nothing happen.