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

Tables help please?

I'm new to this Tables thing, the one that goes like this ["Random", 20, true]. I just need help on one little thing.

I have the following table:

a = [109412, 1210542, 24541]

I want to randomly pick one number and set the script's Parent's name to that number. Would it be something like this:

ab = script.Parent
ab.Name = ""..#a

Thanks for your help!

3 answers

✓ Accepted answer

Tables in Lua are created using curly braces. Square braces are used to access table members.

a = {109412, 1210542, 24541}
script.Parent.Name = a[math.random(#a)]

3 comments

1

Helped a lot. Thanks!

0

Does this select 1 or more??

0

Exactly one.

u can also do

a = {109412, 1210542, 24541}
script.Parent.name = a[math.random(1, #a)]

2 comments

0

That's exactly what the guy above did...

0

-_- he didn't do 1, #a :P thats y I said this...

sorry i think i fixed it

a = {109412, 1210542, 24541}
ab = script.Parent
ab.Name = "" ..a[math.random(1, #a)]

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