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)
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)
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 . 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)
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.
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
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)