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

Problem with an if statement and checking if a part in a tool is a certain colour, any solutions?

I'm bug fixing and making sure that once a part in a tool changes colour, it stays that colour by doing a simple check. Here is the code that I have tried so far:

-- Adding vanilla flavour
game.Workspace.flavours.addVanillaFlavour.Touched:Connect(function(Object)
	if Object.Parent:FindFirstChild("Milk") then
		if Object.Parent.Milk.BrickColor == ("Institutional white") then
			Object.Parent.Milk.BrickColor = BrickColor.new("Cool yellow")
			Object.Parent.Parent.Name = ("Milk with Vanilla")	
		end
	end
end)


The problem is 100% the if statement checking if the colour is Institutional white, but I'm unsure of why it isn't working as when I remove that line it works normally.

However, there is a problem saying 'BrickColor is not a valid member of Tool', even though if I remove the if statement the code still works. If you understand what I mean, please be sure to answer! :)

1 answer

✓ Accepted answer
Object.Parent.Milk.BrickColor == ("Institutional white")

this compares a BrickColor to a String, which obviously will never be true

try

Object.Parent.Milk.BrickColor == BrickColor.new("Institutional white") 

2 comments

0

I don't want the BrickColour to change to white, I want it to check if it is white to change it to yellow.

0

Nevermind, got it. Thanks for the solution. :D

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