There is no such thing as 'Material.random', kinda how there is 'BrickColor.random'. But I am trying to make a script when I click a TextButton, a part will turn a random material that is in the table.
local player = game.Players.LocalPlayer
local Materials = {'Brick', 'Concrete', 'Cobblestone'} --Table of Part Materials
script.Parent.MouseButton1Click:connect(function()
local PlayersHome = player.PlayersHome
if PlayersHome.Value ~= nil then
local Walls = player.PlayersHome.Value.House.Walls
for i,v in pairs(Walls:GetChildren()) do
if v:IsA('UnionOperation') or v:IsA('Part') then
local selectedstring = Materials[math.random(1,#Materials)] --Here is the main code I am looking for.
v.Material = Enum.Material.selectedstring
end
end
else
script.Parent.Parent.Parent.Parent.FailFolder.Fail2.Visible = true
end
end)

6 comments
Right away I get "Materials is not a valid EnumItem" in output.
On line 3
Oops, my mistake, it's Material, not Materials.
I get "Players.Player1.PlayerGui.Main.BottomContainer.Buttons.HomeMaterial.LocalScript:6: bad argument #1 to 'pairs' (table expected, got Enum)"
Replace
local oMaterials = Enum.MaterialwithoMaterials = Enum.Material:GetEnumItems().Ah, is that the problem? Enums are their own special value type?