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"
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"
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.
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.
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]
What specifically isn’t working? Are there any errors in output?
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]
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.
String needs to be without the enum.Material, try the one I sent
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
.