Survivor System

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

spawn(roundTimer)

Can you please provide more information besides saying it’s not working?

1 Like

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.

1 Like

In this script , I don’t see you adding all the player’s to a Table . Show the script where you are adding them to the table

1 Like

–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

1 Like

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.

@SloppyBanana225 can you please explain us a bit more further about your script? we meet again @Razor_IB

1 Like

one last thing, how would I put the table into a textlabel?

what do you mean???

Fire a remote event to all Client , loop through the table and to a variable add the each player’s Name as a String and set it as the TextLabel’s Text

can you please do this and maybe i can help???

can you please do this and maybe i can help???

and how would I go about doing that?

pretty much

I told how to do it, I explained it well.

I’m sorry I just don’t see how firing to all clients will benefit at the server, and how would I check the active players through the table?

You want to show it on a text label and GUI should be handled on client , so fire a remote event to every client and change the Text.

1 Like

if you want:
FireAllClients
in pairs loop
baesic
last

what would be the script to fire to all remaining clients through the table and check to see if they have survived?

pretty much, so the whole server can see the changes to the text i can VERY much see your a begginer