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

Tables help please?

Asked by 10 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:

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

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

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)]
1
Helped a lot. Thanks! fahmisack123 385 — 10y
0
Does this select 1 or more?? fahmisack123 385 — 10y
0
Exactly one. adark 5487 — 10y
Ad
Log in to vote
0
Answered by
KAAK82 16
10 years ago

u can also do

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

sorry i think i fixed it

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

Answer this question