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

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

Asked by 8 years ago

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

Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

.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
Ad
Log in to vote
-1
Answered by
3x6x0 0
8 years ago

this is what i think it would be

for _,v in pairs do
    if v.Material = Material.Concrete then
        v.Name = "NotMe"
    end
end
Log in to vote
-2
Answered by 8 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.
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
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. General_Scripter 425 — 8y

Answer this question