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

How do I convert an array to a string?

Im trying take the first index number of an array and use it to change the text of a texbutton like so

local array = {}
local players = game.Players:GetPlayers()
for i=1,#players do
    table.insert(array,players[i])
end

and

game.Players.LocalPlayer.PlayerGui.ScreenGui.Frame.player1.Text = array[1]

1 comment

0

array[1].Name; look at tostring and table.concat() for actual conversions.

3 answers

Thanks Kingdomas I found a shitty way of using it by doing this

local sp1 = tostring(array[1])
local sp2 = tostring(array[2])
local sp3 = tostring(array[3])
local sp4 = tostring(array[4])
local sp5 = tostring(array[5])

well it works lmao

local Array = {1, 2, 3, "text1"}
local String = '' 

for i,v in pairs(Array) do
	String = String..' '..v
end

print(String) -- Output: 1 2 3 text1

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