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

"If v:Material("MaterialName") then v.Name = "Blah""?

So. I'm trying to make this script that goes through my model and check's if the Part's material is Concrete, and if it is, it changes its name...

A = game.Workspace.This:GetChildren()

for i,v in pairs(A) do
    if v:Material("Concrete") then
	n.Name = "NotMe"
    end
end

3 answers

✓ Accepted answer

.Material is not a method, it is a property. That means v.Material is a value of some kind.

The Material property page on the Wiki will tell you that the value is a Material Enum.

Since you want to compare the material to Concrete to see if they are equal, you're probably going to use ==.

You can either compare the name of the material, or directly compare enums. Comparing one kind to the other kind will always return false since == first compares the types of the objects.

Since you will get an error if you mistype an enum name when using the Enum. option, that's probably better:

if v.Material == Enum.Material.Concrete then

this is what i think it would be

for _,v in pairs do
	if v.Material = Material.Concrete then
		v.Name = "NotMe"
	end
end
A = game.Workspace.This:GetChildren()

for i,v in pairs(A) do
	if v.Material = Enum.Material.Concrete then
	v.Name = "NotMe"
	end
end

1 comment

1

Although this may be the answer, you should probably provide some reason as to what they did wrong and how you would go about fixing it. Although code can be helpful, your answer should still provide some reasoning.

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