Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I get all the values of a table into a single string?

The question says it all, however I'll explain my question in more detail...

While this isn't my particular case, it has the same problem.

Let's say I have a table of all the players in my game and I want to automatically send it to a trello board at a certain time. I need to put those names in the description of a card. I would usually do

local description = ('Players in game: '..Players[1]..', '..Players[2])

however I don't know how many names are in the table. I need to send the whole table but it's difficult as the number of players in the table will not always be the same so I can't do the method I've just shown. Is it possible to get ROBLOX to send the whole table?

Sorry if I've written everything badly. Any help is appreciated!

2 answers

✓ Accepted answer

You can also use table.concat, this will only work for arrays.

Example:-

local a = {'player1','player2', 'player3'}

print('players:- ' .. table.concat(a,', '))

Output:- players:- player1, player2, player3

I hope this helps.

2 comments

0

Arrays of strings and numbers, to be precise. If you have other objects in your list, you'll get an error.

0

Actually, that was exactly what I was looking for. Thanks!

You would use a FOR loop in order to do this.

Here's some examples:

SomePlayerList=game.Players:GetPlayers()

for i,v in pairs(SomePlayerList) do
print("Players name is "..v.Name)
end

--Example 2

SomeTable={"Apple","Orange","Kiwi"}

for i=1,#SomeTable do
print("Name is "..SomeTable[i])
end

Both ways would produce the same result. When using ipairs, the first value returns the current index number of the table,the second returns the value/object of the table.

If this is the answer you were looking for,be sure to mark it as the answer so others can read it in the future!

This discussion is preserved as it was. New answers, comments, and votes are closed.