(SOLVED) Select a random material efficiently?
Asked by
5 years ago Edited 5 years ago
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.
1 | local mat = { "Plastic" , "SmoothPlastic" , "Neon" , "Wood" , "WoodPlanks" , "Marble" , "Slate" , "Concrete" , "Granite" , "Brick" , "Pebble" , "Cobblestone" , "CorrodedMetal" , "DiamondPlate" , "Foil" , "Metal" , "Grass" , "Sand" , "Fabric" , "Ice" } |
3 | local children = script.Parent.LeftBackLeg:GetChildren() |
4 | for i, child in ipairs (children) do |
5 | local material = mat [ math.random( 0 , 19 ) ] |
6 | child.Material = Enum.Material.material |
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