Hello there, I made a script in which the part named "painter" randomizes the color of another part named "Cover" with the math.random script, however upon trying it the Cover only appears as color Gold with the Paper aswell colored as Gold even though my script clearly says that the Paper should be white, how do I fix this?
NOTE: There is a script inside the "Cover" part which is just cloning it along with it's children
local RandomColorGenerator = math.random(1, 5) local Cover = game.Workspace:WaitForChild("Cover") local Paper = Cover.Paper local painter = script.Parent painter.Touched:Connect(function(Cover) if RandomColorGenerator == 1 then Cover.BrickColor = BrickColor.new("Navy blue") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 2 then Cover.BrickColor = BrickColor.new("Maroon") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 3 then Cover.BrickColor = BrickColor.new("Gold") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 4 then Cover.BrickColor = BrickColor.new("Magenta") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 5 then Cover.BrickColor = BrickColor.new("Sea green") Paper.BrickColor = BrickColor.new("White") end end)
You wanna get a random number every time you touch it, so you use the math.random function every time you touch it:
local Cover = game.Workspace:WaitForChild("Cover") local Paper = Cover.Paper local painter = script.Parent painter.Touched:Connect(function(Cover) local RandomColorGenerator = math.random(1, 5) if RandomColorGenerator == 1 then Cover.BrickColor = BrickColor.new("Navy blue") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 2 then Cover.BrickColor = BrickColor.new("Maroon") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 3 then Cover.BrickColor = BrickColor.new("Gold") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 4 then Cover.BrickColor = BrickColor.new("Magenta") Paper.BrickColor = BrickColor.new("White") end if RandomColorGenerator == 5 then Cover.BrickColor = BrickColor.new("Sea green") Paper.BrickColor = BrickColor.new("White") end end)