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

Tables help please?

Asked by 11 years ago

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:

1a = [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:

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

Thanks for your help!

3 answers

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
11 years ago

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

1a = {109412, 1210542, 24541}
2script.Parent.Name = a[math.random(#a)]
1
Helped a lot. Thanks! fahmisack123 385 — 11y
0
Does this select 1 or more?? fahmisack123 385 — 11y
0
Exactly one. adark 5487 — 11y
Ad
Log in to vote
0
Answered by
KAAK82 16
11 years ago

u can also do

1a = {109412, 1210542, 24541}
2script.Parent.name = a[math.random(1, #a)]
0
That's exactly what the guy above did... fahmisack123 385 — 11y
0
-_- he didn't do 1, #a :P thats y I said this... KAAK82 16 — 11y
Log in to vote
-1
Answered by
LAC44 20
11 years ago

sorry i think i fixed it

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

Answer this question