All terrain materials are plastic

Ok, so I am trying to make a mining game that uses terrain, and I want the speed of the mining to be based off of the material of the terrain. the only problem is…

script.Parent.Touched:Connect(function(Touch)
	if Touch:IsA("Terrain") then
		if Touch.Material == Enum.Material.Plastic then -- But it's salt
			print("Every single terrain material output is plastic, even though it is not.")
			-- This makes it very hard to find the material of terrain.
		end
	end
end)

How can I fix this?

Please respond with a clear answer because I’m new to roblox.

2 Likes

I feel like this should be working, but you should check if its the terrain material that you said it was. if its still the same then i dont know how to help you as i am not experienced with terrain scripting.

You have to use raycasting to get the material of a specific terrain point.

Well, you know that the terrain is not plastic, so no. that’s not the problem.

I don’t know anything about raycasting. Can you please send me a script for it?

You most likely need to do a raycast from one of the body parts of your character and a few studs forward.

I’d recommend learning here how to use Raycasting, for the direction of the ray you need to use the LookVector of the body part’s CFrame multiplied by a distance it checks, 3-5 would be ideal for you

Touched only really works for parts, it doesn’t work well for Terrain

Though raycasting constantly when a part touches would be expensive so you should probably make it raycast after activating the tool through the Activated event

1 Like

Thanks! I’ll read the dev hub link.

1 Like

Here’s the documentation for raycasting. You can use RaycastResult.Material to get the material.

1 Like

Cool! Thanks for the support everyone!