if hit.Material == Enum.Material.Concrete or hit.Material == Enum.Material.Slate or hit.Material == Enum.Material.Brick or hit.Material == Enum.Material.Granite or hit.Material == Enum.Material.Marble or hit.Material == Enum.Material.Cobblestone then
How could i make it shorter?
I tried this:
concrete = {Enum.Material.Concrete,Enum.Material.Slate,Enum.Material.Brick, Enum.Material.Granite,Enum.Material.Marble,Enum.Material.Cobblestone}
if hit.Material == concrete then
But it’s didn’t work. I don’t know much about tables/arrays
local Materials = {Enum.Material.Concrete,Enum.Material.Slate,Enum.Material.Brick, Enum.Material.Granite,Enum.Material.Marble,Enum.Material.Cobblestone}
if table.find(Materials, hit.Material) ~= nil then
end
local materials = {
Enum.Material.Concrete,
Enum.Material.Slate,
Enum.Material.Brick,
Enum.Material.Granite,
Enum.Material.Marble,
Enum.Material.Cobblestone
}
if table.find(materials, hit.Material) then
-- your code here
end
local isconcrete = hit.Material == Enum.Material.Concrete
local isSlate = hit.Material == Enum.Material.Slate
local isSltOrCrete = isconcrete or isSlate
local Brick = hit.Material == Enum.Material.Brick
local Granite = hit.Material == Enum.Material.Granite
local BrickOrGrn = Brick or Granite
local SOCorBOG = isSltOrCrete or BrickOrGrn
local Marble = hit.Material == Enum.Material.Marble
local Cobble = hit.Material == Enum.Material.Cobblestone
local MrbOrCob = Marble or Cobble
local IsOneOfThem = SOCorBOG or MrbOrCob
if IsOneOfThem then
-- Code here
end
Or If you prefer saving lines too try this
materials = {
Enum.Material.Concrete,
Enum.Material.Slate,
Enum.Material.Brick,
Enum.Material.Granite,
Enum.Material.Marble,
Enum.Material.Cobblestone
}
if table.find(materials, hit.Material) ~= nil then
-- code here
end
The fact is that I have several such checks on the material.
So i want to do this:
Concrete = {Concrete type materials}
Metal = {Metal type materials}
Wood = {Wood type materials} -- lazy to write every material, so just this
if hit.Material == Concrete then
--do concrete thing
elseif hit.Material == Metal then
--do metal thing
elseif hit.Material == Wood then
--do wood thing
end