Issue with a Shovel script

Hi, Guys, I made a shovel script that allows you to dig in the smooth terrain however there is a problem when it comes to digging grass, it is just not working (Works with different materials fine).

Here is script:

   local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer

local tool = script.Parent.Parent.Parent.Shovel

local vector = Vector3.new(1,1,1)
local resolution = 4

local digremote = game.ReplicatedStorage:WaitForChild("Dig")

local function GetDistance(p1,p2)
	local Distance = (p1.Position - p2.Position).magnitude
	return Distance
end


tool.Equipped:Connect(function(mouse)
	mouse.Button1Down:Connect(function()
		if mouse.Target and mouse.Target.Parent then
			if(mouse.Target.Name == "Terrain") then
				local Mpos = mouse.hit.p
				local MRegion = Region3.new(mouse.hit.p - vector,mouse.hit.p + Vector3.new(1,1,1))
				MRegion = MRegion:ExpandToGrid(resolution)
				local material = workspace.Terrain:ReadVoxels(MRegion,resolution)
				local size = material.Size
				for x = 1, size.X do
					for y = 1, size.Y do
						for z = 1, size.Z do
							local mat = material[x][y][z]
							if mat == Enum.Material.Cobblestone or mat == Enum.Material.Grass or mat == Enum.Material.Mud then
								if GetDistance(mouse.hit, localPlayer.Character.HumanoidRootPart) < 10 then					
										digremote:FireServer(mouse.hit.p)						
								end					
							end
						end
					end
				end
			end
		end
	end)
end)

Was there an error or did it just not work?

There isn’t anything in the console so I guess there aren’t any errors.

hmm well im not to sure, but it could be that grass has a different name than grass, but idk, like DecoratedGrass, not that exactly but something like it, could be strangely named

I found out that I can make a list of not diggable materials, not vice versa and that fixed my issue.
@TheBaconHero_101 thanks for the help though. :+1:

1 Like