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

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

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.

2 comments

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") .

0

thanks

1 answer

✓ Accepted answer

###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

1 comment

0

thanks! i had a huge brain fart lmao

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