What do you mean exactly?.. Do you have a table of Player’s that survived, and you want to print them all in one sentence, with “Survivors:” printed in front?
local Table = {"Charles", "Richard", "Leopold"}
local newString = "Survivors: "..table.concat(Table, ", ")
print(newString)
To break down “concat”, it takes the table, takes one value at a time (Charles then Richard ect. ect), seperates them in this case by a comma and a space, since we said ", ". You can make any seperator, it could even be " - "
Status.Value = 'Survivors: '
for i, char in pairs(survivors) do
if char then
Status.Value ..= char.Name
if i < #survivors then
Status.Value ..= ', '
end
end
end
I assume that is because, you have inserted the players into the table, and not the player names. So first you gotta convert the player instances into player names.
Player.Names are actually just a string, where as the “Player” is a instance object. You can also use player names for debounces, so a killbrick would work for more than one player at the same time
local Players = game.Players
local Debounce = {}
Brick.Touched:Connect(function(Hit)
local C = Hit.Parent
local H = C:FindFirstChildOfClass("Humanoid")
if H and H.Health > 0 then
local Player = Players:GetPlayerFromCharacter(C)
if Player and not Debounce[Player.Name] then
Debounce[Player.Name] = true -- inserts the player name
H:TakeDamage(10)
task.wait(0.25)
Debounce[Player.Name] = nil -- removes the player.name
end
end
end)
local SurvivorsName = {}
for i, player in pairs(PLAYERS:GetPlayers()) do
if player:FindFirstChild("Alive") then
table.insert(survivors, player)
table.insert(SurvivorsName, player.Name)
end
end
if you’d mind here’s my full script also how would i know if the player is already in the table so i can stop inserting it
function Round.StartRound(timer)
local outcome
local survivors = {}
local SurvivorsName = {}
for i= timer, 0, -1 do
for i, player in pairs(PLAYERS:GetPlayers()) do
if player:FindFirstChild("Alive") then
table.insert(survivors, player)
table.insert(SurvivorsName, player.Name)
end
end
Status.Value = toms(i)
--if #survivors <= 1 or #survivors == 1 then
-- outcome = "1-player-left"
-- break
--end
if #survivors <= 0 or #survivors == 0 then
outcome = "all-players-died"
break
end
if i <= 0 or i == 0 then
outcome = "time-up"
break
end
task.wait(1)
end
--local Table = {"Charles", "Richard", "Leopold"}
--local newString = "Survivors: "..table.concat(Table, ", ")
--print(newString)
if outcome == "all-players-died" then
Status.Value = "No Survivors Left"
elseif outcome == "time-up" then
Status.Value = "Survivors: "..table.concat(SurvivorsName, ", ")
elseif outcome == "1-player-left" then
Status.Value = "Survivor: "..SurvivorsName[1].."."
end
end
Each time you check for suvivors, you should reset the table.
local survivors = {}
local SurvivorsName = {}
for i= timer, 0, -1 do
survivors = {}
SurvivorsName = {}
for i, player in pairs(PLAYERS:GetPlayers()) do
if player:FindFirstChild("Alive") then
table.insert(survivors, player)
table.insert(SurvivorsName, player.Name)
end
end
Here’s the fully updated script. I fixed some minor stuff
function Round.StartRound(timer)
local outcome
local survivors = {}
for i= timer, 0, -1 do
survivors = {}
for i, player in pairs(PLAYERS:GetPlayers()) do
if player:FindFirstChild("Alive") then
table.insert(survivors, player)
end
end
Status.Value = toms(i)
--if #survivors <= 1 then
-- outcome = "1-player-left"
-- break
--end
if #survivors == 0 then
outcome = "all-players-died"
break
end
if i == 0 then
outcome = "time-up"
break
end
task.wait(1)
end
if outcome == "all-players-died" then
Status.Value = "No Survivors Left"
elseif outcome == "time-up" then
local WinnerNames = {}
for i, player in pairs(survivors) do
table.insert(WinnerNames,player.Name)
end
Status.Value = "Survivors: "..table.concat(WinnerNames, ", ")
elseif outcome == "1-player-left" then
Status.Value = "Survivor: "..SurvivorsName[1].."."
end
end