Terrain snowplow not working

I’m trying to make a part that when touched, if it touches on terrain and the material is snow then it will delete the area that its touching. So far it just doesn’t do anything and the print keeps printing the plastic material for some reason.

local snowPart = script.Parent

snowPart.Touched:Connect(function(hit)
	if hit:IsA("Terrain") then
		print(hit.Material)
		
		if hit.Material == "Snow" then
			workspace.Terrain:FillBlock(snowPart.CFrame, snowPart.Size, Enum.Material.Air)
		end
	end
end)
1 Like

I think you have to do something with raycasting because I don’t think that it works using .Touched cause I saw another topic that said that a salt material was plastic too. You can use RaycastResult.Material to get it. You can use the snowparts look vector to get the direction for the raycast.

Edit:
Also right after the look vector put

snowPart.CFrame.LookVector * 2 --raycast goes two studs
-- so that you can't do it from far away.

Is the snowPart touching another Part that is Plastic?
Do you have the snowPart CanTouch property set to false?

nvm about last reply. I tested it out and I got something that worked.
Here is the script:

local snowPart = script.Parent

local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude 
params.FilterDescendantsInstances = {snowPart} 

while task.wait() do
	ray = workspace:Raycast(snowPart.Position, snowPart.CFrame.LookVector * 1, params)
	if ray and ray.Instance then
		print(ray.Material)
		if ray.Material == Enum.Material.Snow then 
			print("It is snow")
			workspace.Terrain:FillBlock(snowPart.CFrame, snowPart.Size*3, Enum.Material.Air)
		end
	end
end

Tried it out and it worked. Here is a video too with a modified script to get the part to move

Of course all you have to do is adjust some of the stuff to get it to work with yours and also place your snowplow into the filter list so it works properly.