headbane = script.Parent.Parent.TMNT.Chest.Band x = game.Workspace.TMNT.Chest.Band blue = script.Parent.Parent.Colors["Bright Blue"].Value purple = script.Parent.Parent.Colors["Bright Violet"].Value orange = script.Parent.Parent.Colors["Bright Orange"].Value red = script.Parent.Parent.Colors["Bright Red"].Value quite = script.Parent.Parent.Colors:GetChildren()
colorer = {"Bright blue", "Bright red", "Bright orange", "Bright violet"} goodie = #colorer blue = 1 orange = 2 red = 3 blue = 4
script.Parent.MouseButton1Click:connect(function()
x.BrickColor = headbane.BrickColor
script.Parent.Color.Text = headbane.BrickColor.Name
if script.Parent ~= nil then
if script.Parent.MouseButton1Click then
script.Disabled = true
headbane.BrickColor.Value = BrickColor.new(math.random(goodie))<-----Need Help Here...
end
script.Disabled = false
end
end)
To select a random element from a list list
, we select a random index from that list
:
randomIndex = math.random(1,#list)
Then ask for the element at that randomIndex
:
randomElement = list[randomIndex]
In this case, randomElement
is a string but we want a BrickColor
from it, so we use
randomColor = BrickColor.new(randomElement)
All in one line:
randomColor = BrickColor.new(colorer[math.random(1,#colorer)])