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

Random and Arrays?

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

1 comment

0

because randName isn't an actual name it's just a number value.

1 answer

✓ Accepted answer

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

2 comments

0

That string concatenation is completely useless...

0

what do you mean

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