I’m trying to write an elseif loop to check for a certain number (using math.Random). It will check that number, then go into a folder called “Circles” and pull out the respective part.
How can I make it so I don’t have to repeat myself so much?
Here’s my code:
local val = math.Random(1, 20)
if val == 1 then
local cX = circles.Circle1.Position.X
local cY = circles.Circle1.Position.Y
local cZ = circles.Circle2.Position.Z
-- repeat until 20
You can take the value of the val variable and concatenate the string "Circle" to it to generate a name of a circle that you can use to index circles with.
local val = math.random(1, 20)
local circle = circles["Circle" .. val]
local position = circle.Position
local cX = position.X
local cY = position.Y
local cZ = position.Z