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

Random and Arrays?

Asked by 7 years ago

So I created an Array with loads of names. then used math.random to select a random name but it always gives me a number between 1 and however many there are. Here is the code.

local names={"Tom", "Jesse", "Olivia"}
local randName=math.random(1, #names)
script.Parent.BasePlate.Name=""..randName
0
because randName isn't an actual name it's just a number value. Senor_Chung 210 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago

try this:

local names={"Tom", "Jesse", "Olivia"}
local randName=math.random(1, #names)
local actualname = names[randName]
workspace.Baseplate.Name=""..actualname

you're trying to rename baseplate to randName which isnt a string value, but a number value. what you have to do is then use randName and actually choose that variable from your array

0
That string concatenation is completely useless... Link150 1355 — 7y
0
what do you mean Senor_Chung 210 — 7y
Ad

Answer this question