Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
lokkut 20
5 years ago
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") 
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. RyanTheLion911 195 — 5y
0
Nevermind, got it. Thanks for the solution. :D RyanTheLion911 195 — 5y
Ad

Answer this question