How can randomly choose left from right

Ok so Im trying to make a script that chooses a random part out of two to make it transparent

local parts = {part1, part2}

parts[math.random(#parts)].Transparency = 1
1 Like

One way to do, put parts in a table then do math.random() to pick from it.

local parts = {
PathToPart1,
PathToPart2
}
local randompart = parts[math.random(1,#parts)]
randompart.Transparency = 1

Another way, define the variables:

local part1 = PathToPart1
local part2 = PathToPart2
local randomnumber = math.random(1,2)
if randomnumber == 1 then
part1.Transparency = 1
elseif randomnumber == 2 then
part.Transparency = 1
end