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

Naming every block that is a certain material script isn't working?

Asked by 4 years ago
Edited 4 years ago

I'm putting this script into the command bar of studio

for _, object in pairs(game.Workspace.Model:GetChildren()) do

if object.Material == "Marble" then

object.Name = "Hi"
end

end

I'm trying to make every single block in Workspace thats material is Marble be named "Hi" - Why isn't this working? No errors.

0
It probably works, but you can't see the exact state of objects while you're testing a game. SuperQmod 18 — 4y
0
It also might be because you're typing it into the command bar and not putting it into an actual script. SuperQmod 18 — 4y
0
SuperQmod, don't the official Roblox scripting tutorial videos use the command bar in such a way? customtshirts 2 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago

Enums


So, if you were were to create a new part, set its material to "Plastic", and run this line of code in a script inside the part:

print(script.Parent.Material == 'Plastic')

This would print false, as the material of the part is an Enumeration (enum) value not equal to the string "Plastic"

With that said, the following line would print "true"

print(script.Parent.Material == Enum.Material.Plastic)

So, a fixed version of your script would be something like:

for _, object in pairs(game.Workspace.Model:GetChildren()) do
    if object.Material == Enum.Material.Marble then
        object.Name = "Hi"
    end
end
0
The answer by Theking would probably fix your issue XXDLOLXDDILMOA 55 — 4y
Ad

Answer this question