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

Why won't this if statement change only plastic objects to smoothplastic?

Asked by 5 years ago

I'm a bit of a beginner to scripting and I wanted to make a plugin that changes selected objects from plastic to smoothplastic.

if Obj.Material == "Plastic" and Obj.ClassName == "Part" or Obj.ClassName == "WedgePart" or Obj.ClassName == "CornerWedgePart" or Obj.ClassName == "UnionOperation" or Obj.ClassName == "TrussPart" or Obj.ClassName == "SpawnLocation" then
        Obj.Material = "SmoothPlastic"
end

For some reason when i selected a plastic part and activated it the material stayed the same. However when I used a WedgePart it changed to smoothplastic, but it would still change to smooth plastic even when it wasn't plastic. This question probably will make you professional script builders cringe, but i can't figure out how to make this work.

0
The issue is most likely to due with the order of the if statement. Is stating if the object is Plastic and the has the class name equal to part or if it is a wedge part. Hard to explain but when putting or statements it is best to use parenthesis. But anyway this could all be avoided if you instead use :IsA("BasePart") . Bluemonkey132 194 — 5y
0
thanks yoMomIsCrusty 7 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

You do not need to check for individual classes! You can use IsA. This will return true if the object inherits from specified class. Also, it doesn't work because Material is an enum, not a string.

if Obj.Material == Enum.Material.Plastic and Obj:IsA("BasePart") then
0
thanks! i had a huge brain fart lmao yoMomIsCrusty 7 — 5y
Ad

Answer this question