Hello everyone.
My game involves selecting a random material for lots of separate objects. First, I attempted this by selecting a random material from an array, and then setting the object's material to that.
local mat = {"Plastic","SmoothPlastic","Neon","Wood","WoodPlanks","Marble","Slate","Concrete","Granite","Brick","Pebble","Cobblestone","CorrodedMetal","DiamondPlate","Foil","Metal","Grass","Sand","Fabric","Ice"} local children = script.Parent.LeftBackLeg:GetChildren() for i, child in ipairs(children) do local material = mat[math.random(0,19)] child.Material = Enum.Material.material end
This gave me the error: "material is not a valid EnumItem" which I suppose makes sense because I said to set it to that? But I already selected a random material from the array which confuses me.
Is there any way to do this besides select a random number using math.random and saying if it's that number it selects a different material (extremely tedious).
Thanks! :D
Instead of Enum.Material.material
you should put Enum.Material[material]
.
If that doesn't work, then you can do child.Material = material
because changing the material property can also be done by putting the material's name in a string.