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
01 | local RandomColorGenerator = math.random( 1 , 5 ) |
02 | local Cover = game.Workspace:WaitForChild( "Cover" ) |
03 | local Paper = Cover.Paper |
04 | local painter = script.Parent |
05 |
06 | painter.Touched:Connect( function (Cover) |
07 | if RandomColorGenerator = = 1 then |
08 | Cover.BrickColor = BrickColor.new( "Navy blue" ) |
09 | Paper.BrickColor = BrickColor.new( "White" ) |
10 | end |
11 | if RandomColorGenerator = = 2 then |
12 | Cover.BrickColor = BrickColor.new( "Maroon" ) |
13 | Paper.BrickColor = BrickColor.new( "White" ) |
14 | end |
15 | if RandomColorGenerator = = 3 then |
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?
You wanna get a random number every time you touch it, so you use the math.random function every time you touch it:
01 | local Cover = game.Workspace:WaitForChild( "Cover" ) |
02 | local Paper = Cover.Paper |
03 | local painter = script.Parent |
04 |
05 | painter.Touched:Connect( function (Cover) |
06 | local RandomColorGenerator = math.random( 1 , 5 ) |
07 | if RandomColorGenerator = = 1 then |
08 | Cover.BrickColor = BrickColor.new( "Navy blue" ) |
09 | Paper.BrickColor = BrickColor.new( "White" ) |
10 | end |
11 | if RandomColorGenerator = = 2 then |
12 | Cover.BrickColor = BrickColor.new( "Maroon" ) |
13 | Paper.BrickColor = BrickColor.new( "White" ) |
14 | end |
15 | if RandomColorGenerator = = 3 then |
So I don't know why this works but I have a theory. It might be because it needs another part to touch it in the original script so you have to know if a player touched it for it to work. I used this Article by roblox to fix this. Also the reason its so different is because when I tried to test the code in studio it wouldn't work what so ever.
01 | local Cover = workspace:WaitForChild( "Cover" ) |
02 | local Paper = Cover.Paper |
03 | local painter = script.Parent |
04 |
05 | local function onPartTouched(otherPart) |
06 | local RandomColorGenerator = math.random( 1 , 5 ) |
07 | local partParent = otherPart.Parent |
08 |
09 | -- Look for a humanoid in the parent |
10 | local humanoid = partParent:FindFirstChildWhichIsA( "Humanoid" ) |
11 | if humanoid then |
12 | if RandomColorGenerator = = 1 then |
13 | Cover.BrickColor = BrickColor.new( "Navy blue" ) |
14 | Paper.BrickColor = BrickColor.new( "White" ) |
15 | elseif RandomColorGenerator = = 2 then |