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

Beginner color change if statement not working?

Hey, so as you can see I am trying to make a part change it's color to blue after being clicked, which happens but it does not get destroyed as it should, why is that? I would then like to do so the BrickColor = BrickColor.Random() and when the color would become blue it would destroy itself, thanks.

function ColorChange()

	
script.Parent.BrickColor = BrickColor.Blue()
	

	if BrickColor == BrickColor.Blue() then
		script.Parent:Destroy()
end
	
end	

		
script.Parent.ClickDetector.MouseClick:Connect(ColorChange)

1 answer

✓ Accepted answer

You wrote if BrickColor == BrickColor.Blue(). You forgot to write script.Parent before writing BrickColor. Try this:

local function ColorChange()


	script.Parent.BrickColor = BrickColor.Blue()


	if script.Parent.BrickColor == BrickColor.Blue() then
		script.Parent:Destroy()
	end
end 


script.Parent.ClickDetector.MouseClick:Connect(ColorChange)

7 comments

0

Thank you!

0

No problem. Please mark my answer as the answer to your question.

0

We both earn reputation if you do that.

0

Sorry this is my first time using this site. How do I do it?

0

It should be next to my answer or under it.

0

Okay done, sorry for taking so long but I didn't have the accept answer button on my screen, so I tried it in incognite and it was there. Really weird.

0

Weird. Alright, thanks.

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