Make it so shovel can dig only specific material, instead of everything

Overall, I need a shovel to dig only specific materials, these are: grass, leafy grass, snow, sand. Is it possible to be done on roblox? If so, where’s the error could be at?

function fill(player,blob)
	if Enum.Material.Grass or Enum.Material.Snow or Enum.Material.LeafyGrass or Enum.Material.Sand then
		workspace.Terrain:FillBlock(CFrame.new(blob),Vector3.new(7,7,7),--[[mouse.Target.Material]]Enum.Material.Air)
	else
		print("no")
	end
end
script.Parent.glob.OnServerEvent:Connect(fill)

Are you trying to dig up something or fill up something? Because your code is saying fill, but you’re saying dig.

It looks like you arent comparing the materials to anything, and that you’re just checking if an enum exists, which will always be true, try adding if SelectedObject.Material == Enum.Material.Grass then (do the rest)

Better yet, you could put all the enums of the materials in a table, create a function to check it, and return true or false if it matches the other materials.

local AcceptedMaterialTable = {Enum.Material.Grass,
Enum.Material.Snow,
Enum.Material.LeafyGrass,
Enum.Material.Sand}

local function CheckMaterial(Object)
 for _,Value in pairs(AcceptedMaterialTable) do
  if Value == Object.Material then
   return true
  end
 end
 return false
end

If the above returns true, that means its a match.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.