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

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

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.

3 comments

0

It probably works, but you can't see the exact state of objects while you're testing a game.

0

It also might be because you're typing it into the command bar and not putting it into an actual script.

0

SuperQmod, don't the official Roblox scripting tutorial videos use the command bar in such a way?

1 answer

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

1 comment

0

The answer by Theking would probably fix your issue

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