Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

adding the names inside from a table to a text label gui?

Asked by 5 years ago
local itemarray = {script.Parent.String1.Value,script.Parent.String2.Value,script.Parent.String3.Value}
local text = script.Parent.Test

text.Text = itemarray[1],itemarray[2],itemarray[3]

Im experimenting with tables and I would like to add the names listed on that table to a gui. this script only adds itemarray[1] .

2 answers

Log in to vote
0
Answered by
HDWC 53
5 years ago

To connect strings in roblox you use .. instead of , So what you want to do is

Text = itemarray[1]..itemarray[2]..itemarray[3]

Your welcome!

0
table.concat() is way easier. DeceptiveCaster 3761 — 5y
0
ok HDWC 53 — 5y
Ad
Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You can use table.concat() to do this:

local str = table.concat(itemarray, " ") -- Concatenate every index in the array with a whitespace between each index
script.Parent.Test.Text = str

So you may be asking "Well, what is table.concat()?". It is a function that concatenates the given array (it can only concatenate arrays, giving it a dictionary will result in an error) with a separator. The parameters that you should pass:

  1. The array to concatenate. As I already said, this parameter must be an array.
  2. The string that acts as the separator between indices. This can be anything you want. With a whitespace as a string (" "), each index is separated by that whitespace. (optional)

With long tables, doing what the other answer did above would take a really long time. It's all about efficiency in programming, which is why you should use table.concat().

Answer this question