I’m working on my weapons system and I ran into the issue of getting the terrain material color at a given point. The best solution I could come up with was this:
local offset = Vector3.new(0.05, 0.05, 0.05) --This doesn't really matter
local hitRegion = Region3.new(hitPoint - offset, hitPoint + offset)
hitRegion = hitRegion:ExpandToGrid(4)
local materials = Workspace.Terrain:ReadVoxels(hitRegion, 4)
for i, material in ipairs(materials) do
local name = material[1][1]
local success = pcall(function()
Workspace.Terrain:GetMaterialColor(name)
end)
if success and name ~= "Air" then
color = Workspace.Terrain:GetMaterialColor(name)
break
end
end
After looking through what was in the materials array, the only material it saw was Air, but there were clearly more materials than just air in the region:

I assume this issue has something to do with how terrain voxels work, so I guess this won’t work. Is there a solution for this?