Hello! I’m trying to make a winner system where it names everyone who survived, I’m trying to use a table but I can’t get it to work any assistance is appreciated! This is my current code: --Game Stats
local roundLength = 45 --Change this value to edit the ingame length
local preroundLength = 20 --Change this value to edit the preround length
local InRound = game.ReplicatedStorage:WaitForChild(“InRound”)
local Lobbyspawn = game.Workspace.LobbySpawn
local GameSpawn = game.Workspace.GameSpawn
local Status = game.ReplicatedStorage:WaitForChild(“Status”)
InRound.Changed:Connect(function()
if InRound.Value == true then
local UpperTilesClone = game.ReplicatedStorage.UpperTiles:Clone()
UpperTilesClone.Parent = game.Workspace
UpperTilesClone.Name = "UpperTiles"
local BottomTilesClone = game.ReplicatedStorage.BottomTiles:Clone()
BottomTilesClone.Parent = game.Workspace
BottomTilesClone.Name = "BottomTiles"
game.Workspace.Bell.Playing = true
wait(1)
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = GameSpawn.CFrame
game.Workspace.ThemeMusic:Play()
end
else
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = Lobbyspawn.CFrame
game.Workspace.UpperTiles:Destroy()
game.Workspace.BottomTiles:Destroy()
end
end
end)
local function roundTimer()
while wait() do
for i = preroundLength, 1, -1 do
local Click = game.Workspace.TimerClick
Click:Play()
InRound.Value = false
wait(1)
Status.Value = “Preround: “… i …” seconds left!”
end
for i = roundLength, 1, -1 do
InRound.Value = true
wait(1)
Status.Value = “Game: “… i …” seconds left!”
end
end
end
I want it to add every player in the server to a table, when a player dies it will remove that player from the table, at the end of the round it will put the survivors names into a text label. Then remove everyone from the table.
–Game Stats
local roundLength = 45 --Change this value to edit the ingame length
local preroundLength = 20 --Change this value to edit the preround length
local InRound = game.ReplicatedStorage:WaitForChild(“InRound”)
local Lobbyspawn = game.Workspace.LobbySpawn
local GameSpawn = game.Workspace.GameSpawn
local Status = game.ReplicatedStorage:WaitForChild(“Status”)
local Table = {}
InRound.Changed:Connect(function()
if InRound.Value == true then
local UpperTilesClone = game.ReplicatedStorage.UpperTiles:Clone()
UpperTilesClone.Parent = game.Workspace
UpperTilesClone.Name = "UpperTiles"
local BottomTilesClone = game.ReplicatedStorage.BottomTiles:Clone()
BottomTilesClone.Parent = game.Workspace
BottomTilesClone.Name = "BottomTiles"
game.Workspace.Bell.Playing = true
wait(1)
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = GameSpawn.CFrame
table.insert(Table, player)
game.Workspace.ThemeMusic:Play()
end
else
for _, player in pairs(game.Players:GetChildren()) do
local char = player.Character
char.HumanoidRootPart.CFrame = Lobbyspawn.CFrame
table.remove(Table, player)
game.Workspace.UpperTiles:Destroy()
game.Workspace.BottomTiles:Destroy()
end
end
end)
local function roundTimer()
while wait() do
for i = preroundLength, 1, -1 do
local Click = game.Workspace.TimerClick
Click:Play()
InRound.Value = false
wait(1)
Status.Value = “Preround: “… i …” seconds left!”
end
for i = roundLength, 1, -1 do
InRound.Value = true
wait(1)
Status.Value = “Game: “… i …” seconds left!”
end
end
end
spawn(roundTimer)
I can’t seem to figure out how to remove them from the table when they die
When the Player joins the game , inside the Character Added event , add an Humanoid.Died event , once they did check if they exist in the table , if they do remove them from table , once the player die disconnect the Humanoid.Died event. The code will look something like
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
char.Humanoid.Died:Connect(function()
if table.find(Table,player) then
table.remove(Table,table.find(Table,player))
end
end)
end)
end)
You can disconect the Humanoid.Died event , so that it doesn’t cause memory leak.