So I have a table with players inside and i want to print every player in a text like this:
“player1, player2, player3” and so on according to how many players that are in the table, but when i do it it only prints one player:
for i, v in pairs(plrs) do
Status.Value = "The winners are: "..v.Name
end
What you do there is change the value #plrs times while not waiting, meaning that what you will see is "The winners are: [last player in table]" instead the silly method is to cache the string, build it and then set it:
local val = "The winners are: "
for i, v in pairs(plrs) do
--imagine this line as adding a player and the comma
val ..= v.Name..", " --val ..= v is equal to val = val..v
end
val = val:sub(1, val:len()-2) --remove the last comma
Status.Value = val
Also as mentioned above you could use table.concat which is the equivalent of the join operation in python(basically what we did above but cooler):
local names = {}
for _, plr in pairs(plrs) do table.insert(names, plr.Name) end
Status.Value = "The winners are: "..table.concat(names, ", ")