I tried making a part with Instance.new. I got it's color, but not the material. The color and the material is both supposed to be random, but the material part has a error saying Invalid value number of the material in math.random for enum Material! Please help. (The area in code that is not working starts from part.Material = math.random (1, 21) do...end )
function onClick(click)
wait(0.05)
local part = Instance.new('Part')
part.Anchored = true
part.Parent = workspace
part.Name = "NewPart"
part.Color = Color3.new(math.random(), math.random(), math.random())
part.Material = math.random(1, 21) do
if part.Material == 1 then
part.Material = "Plastic"
end
if part.Material == 2 then
part.Material = "Wood"
end
if part.Material == 3 then
part.Material = "Wood Planks"
end
if part.Material == 4 then
part.Material = "Slate"
end
if part.Material == 5 then
part.Material = "Concrete"
end
if part.Material == 6 then
part.Material = "Metal"
end
if part.Material == 7 then
part.Material = "Corroded Metal"
end
if part.Material == 8 then
part.Material = "Diamond Plate"
end
if part.Material == 9 then
part.Material = "Foil"
end
if part.Material == 10 then
part.Material = "Grass"
end
if part.Material == 11 then
part.Material = "Ice"
end
if part.Material == 12 then
part.Material = "Brick"
end
if part.Material == 13 then
part.Material = "Sand"
end
if part.Material == 14 then
part.Material = "Fabric"
end
if part.Material == 15 then
part.Material = "Granite"
end
if part.Material == 16 then
part.Material = "Marble"
end
if part.Material == 17 then
part.Material = "Pebble"
end
if part.Material == 18 then
part.Material = "Cobblestone"
end
if part.Material == 19 then
part.Material = "SmoothPlastic"
end
if part.Material == 20 then
part.Material = "Neon"
end
if part.Material == 21 then
part.Material = "Glass"
end
end
part.Position = Vector3.new(-1.582, 6.037, 8.592)
workspace.check.Checker.SurfaceGui.TextLabel.Text = "Part exists, to create different one; destroy it and create a new one."
script.Parent.Disabled = true
end
script.Parent.MouseClick:connect(onClick)

1 comment
Enum.Material, that's the proper way to get a material. But, some of the Materials are terrain-based