How do you cause a part to change ONLY if it has certain properties?

The title seems a bit vague, however I’m new to scripting and have just been messing around trying to figure a few things out. Basically what I’ve done is created a part which changes color when it is stepped on.
(The script I’m using :arrow_down:)

script.Parent.Touched:connect(function(other)
if other and other.Parent:FindFirstChild(“Humanoid”) then
script.Parent.BrickColor = BrickColor.Green()
end
end)

Once I had this script figured out, I attempted to create a similar line of script that would change the color to gray when touched only if the color was green. However, I can’t figure out how to do this. It’s a simple script but I’m unfamiliar to lua. I tried including a requirement for the brick to be green, but the script demands a then statement when I try to define it.

(Script I tried to use to solve issue :arrow_down:)

script.Parent.Touched:connect(function(other)
if other and other.Parent:FindFirstChild(“Humanoid”)and script.Parent.BrickColor = BrickColor.Green then
script.Parent.BrickColor = BrickColor.Gray()
end
end)

Any help would be appreciated. This script isn’t really of the upmost importance but I want to make myself familiar to the way it works.

script.Parent.Touched:connect(function(other)
    if other and other.Parent:FindFirstChild(“Humanoid”) and script.Parent.BrickColor == BrickColor.Green then
        script.Parent.BrickColor = BrickColor.Gray()
    end
end)

you simply need to use “==“ in if statements instead of “=“

1 Like

Ahhh, thank you. This seems to work without error. If I may ask, what’s the difference between = and == in a script?

= will declare a value
== will compare two values

1 Like