I would like to take a random part out of the array and make it Bright green. The issue is that my code sometimes makes 3 parts Bright green, sometimes 2, and sometimes none. I’ve tested to see if print(#math.random(randomizer:GetChildren()) prints the correct number, and it does. So, if it’s checking to see if a number is between 1-24 and the index value matches that random value, why would it be making multiple parts bright green?
workSpace = game:GetService("Workspace")
randomizer = workSpace.Randomizer
for i, v in pairs(randomizer:GetChildren()) do
if i == math.random(1,#randomizer:GetChildren())then
v.BrickColor = BrickColor.new("Bright green")
end
end
Your current code will generate a random number for each part that it loops through, therefore it could never choose a part. Try this instead:
workSpace = game:GetService("Workspace")
randomizer = workSpace.Randomizer
local randomPart = math.random(1, #randomizer:GetChildren())
for i, v in pairs(randomizer:GetChildren()) do
if i == randomPart then
v.BrickColor = BrickColor.new("Bright green")
end
end