Why doesn't conditional statements work with some materials?

image

This doesn’t work. Apparently, the server thinks that the part’s material is not Wood, when it is in fact wood. It however works with smooth plastic

1 Like

Try substituting "Wood" with Enum.Material.Wood.

1 Like

Materials are not of type string, this means when attempting to compare them to a string you should expect it to return false. The solution to this is to compare it with the enum itself, or compare the name of the enum to a string.

Here’s two examples, the first is comparison between two enums.

if script.Parent.Material == Enum.Material.Wood then
    print("YES")
end

While this one is a comparison between two strings.

if script.Parent.Material.Name == "Wood" then
    print("YES")
end
1 Like

The difference in behavior between wood and smooth plastic is definitely odd though

It does not appear to work with Plastic nor SmoothPlastic either though.

print(workspace.Baseplate.Material == "SmoothPlastic") -- false

When the baseplate is set to SmoothPlastic

Ok, that’s good. I wouldn’t have expected it it work for any material. It just seemed strange how @Kevinllululala said it worked for smoothplastic