How could I randomize things, like strings or materials?
local part = Instance.new("Part",workspace)
part.Material = Enum.Material.Grass --I want this to be a random value instead of grass, with it still being a material.
How could I randomize things, like strings or materials?
local part = Instance.new("Part",workspace)
part.Material = Enum.Material.Grass --I want this to be a random value instead of grass, with it still being a material.
Actually I checked with tutorials, but it can't random. Apparently you would need to make a table of all the materials and have it so it randomly chooses from the table.
local part = Instance.new("Part",workspace)
TableMaterial = {"Plastic", "Wood", "WoodPlanks", "Slate", "Concrete", "Metal", "CorrodedMetal", "DiamondPlate", "Foil", "Grass", "Ice", "Brick", "Sand", "Fabric", "Granite", "Marble", "Pebble", "Cobblestone", "SmoothPlastic", "Neon", "Glass"}
part.Material = (TableMaterial[math.random(#TableMaterial)])
There you go :)
Sorry, but the best way is to just do something like this:
And, loop over it with ipairs, or just follow the example.
local materials = {"Glass", "Wood", "etc."}
local rand = math.random(#materials)
part.Material = Enum.Material[materials[rand]]
Hope That Helped.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
I tried that but I'm not sure that's too effective, especially with strings.
There are multiple ways to do it. Like with a Dictionary, like i said, you would want to use ipairs for really any array instead of # since its not that reliable. You probably wont find anythign else besides that.
@Qub_lex, you do need to list what you want to randomize.