script.Parent.Touched:Connect(function(hit)
if hit:IsA("Terrain") then
print(hit.Material)
end
end)
I was checking to see if I can print the material of the terrain using a touch event. but instead of printing the terrain material it prints “Enum.Material.Plastic”( which is weird because the closest source of plastic is the part itself).
If you’re trying to find what material a player is standing on, you should use something like this:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild"Humanoid"
humanoid:GetPropertyChangedSignal"FloorMaterial":Connect(function()
print(humanoid.FloorMaterial)
end)
In addition to FloorMaterial, you can downcast, which is probably what the Humanoid does to get FloorMaterial anyway (unless they use Touched, which would be gross). Downcasting would be just creating a ray between the root and a direction of around 3 studs below the root.
Ray.new(RootPart.Position, Vector3.new(0, -3, 0))
Run that every frame and check the material via FindPartOnRay (the fourth argument specifically).
There is no method on Terrain-like instances for checking what material it is mainly composed of, according to the dev wiki.
.Touched only returns part instances, reading the Terrain's material will always return the Plastic enum.
FindPartsInRegion3 returns an array of part instances with no specific material, and has the same problem as .Touched.
The only way to find the material of a specific part of terrain is by drawing a ray into the region. The material returned should be the material found on that portion of the terrain. The only other alternative method I can think of is storing the material along with the region in a dictionary-like structure. I’m afraid there is nothing else you can use than this.