Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Colour Change Script Not Working?

function whenClicked()
		
		local prim1 = game.Workspace.StarterCar.Red1
		local prim2 = game.Workspace.StarterCar.Red2
		local prim3 = game.Workspace.StarterCar.Red3
		local prim4 = game.Workspace.StarterCar.Red4
		local prim5 = game.Workspace.StarterCar.Red5
		local prim6 = game.Workspace.StarterCar.Red6
		local prim7 = game.Workspace.StarterCar.Red7
		local prim8 = game.Workspace.StarterCar.Red8
		local prim9 = game.Workspace.StarterCar.Red9
		
		prim1.BrickColor = BrickColor.new("Deep Orange")
		prim2.BrickColor = BrickColor.new("Deep Orange")
		prim3.BrickColor = BrickColor.new("Deep Orange")
		prim4.BrickColor = BrickColor.new("Deep Orange")
		prim5.BrickColor = BrickColor.new("Deep Orange")
		prim6.BrickColor = BrickColor.new("Deep Orange")
		prim7.BrickColor = BrickColor.new("Deep Orange")
		prim8.BrickColor = BrickColor.new("Deep Orange")
		prim9.BrickColor = BrickColor.new("Deep Orange")
	
	end
end

script.Parent.MouseButton1Down:connect(whenClicked)

The goal of this script is to change the colour of a brick when a button is pressed (it starts off as red but when the button is pressed it should be orange). The button element of the script works fine, when ever I press the button the colour changes however it changes to white instead of orange. I have also tried using the number values for the colour but it still will not work, can anyone help me?

1 answer

✓ Accepted answer
script.Parent.MouseButton1Down:connect(function()

local Get = game.Workspace.StarterCar:GetChildren()

for i=1,#Get do

if Get[i].Name == "Red" then--I'm predicting you'll change them all to be named Red. for Scripting sake.

Get[i].BrickColor = BrickColor.new("Deep Orange")

end

end

end)
--Forgot the then... Whoopsies.

Reason for what I put: I changed the function code to be a single line for simplicity sake, and then I made it so Get gets the children inside of the script, then it checks each child inside of that part to see if it's name, 'Red' if that's true, then the color will change to Deep Orange like you requested.

7 comments

0

There is a lot of errors in that script, can you fix them and post the clean version?

0

Did you name your parts names to Red? Or no?

0

Yes I did. Here is the error: Players.Player.PlayerGui.Garage.Frame.OrangePrim.PrimaryColourChange:35: ')' expected (to close '(' at line 1) near ''

0

Updated code.

0

The script works, but the colour changes to white.

0

Because Deep orange is spelled with a Lower case 'o'

0

Thank you, it works perfectly now!

This discussion is preserved as it was. New answers, comments, and votes are closed.