Why is this not working?

Hello. I have this script to set a value to the part material and it’s not working

local Part = script.Parent

local Material = Instance.new("StringValue")

Material.Parent = Part

Material.Value = Part.Material

Material.Name = "Material"
2 Likes

Try using tostring(Part.Material) instead of Part.Material — This will turn the Part’s Material into a string, As the Material is an Enum Item.

2 Likes

The part’s Material property value is an enum value, not a string value.

Material.Value = Part.Material.Name -- The name of the Enum not the Enum itself.
1 Like

How do I add that material back to the part

this will not work

part.Material = Material.Value

Did you forget to capitalize Part? If that doesn’t help this is an alternative →

Part.Material = Enum.Material[Material.Value]
1 Like

What specifically isn’t working? Are there any errors in output?

1 Like

there are no errors in output I am trying to change the part material to the value in the part

local Part = script.Parent

local Material = Instance.new(“StringValue”)

Material.Parent = Part

Material.Value = Part.Material.Name

Material.Name = “Material”

Part.Material = Enum.Material[Material.Value]

1 Like

Try this script:

local Part = script.Parent
local Material = Instance.new("StringValue")

Material.Parent = Part
Material.Value = tostring(Part.Material)
Material.Name = "Material"

Part.Material = Enum.Material[Material.Value]

Let me know if that works.

1 Like

I get this error

String needs to be without the enum.Material, try the one I sent

1 Like
local Part = script.Parent
local Material = Instance.new("StringValue")

Material.Parent = Part
Material.Value = tostring(Part.Material.Name)
Material.Name = "Material"

Part.Material = Enum.Material[Material.Value]

This should work-- I forgot that Part.Material returns Enum.Material.Plastic instead of simply Plastic.

1 Like