How would I print the name of a object hit by a raycast?

Im making a ray cast so that my character can go up slower on slopes and down fast on slopes while rolling, I want it to be able to identify the part by printing it in the output.

But I got an error saying that Name is not a Property of RaycastResult, so how can I print and identify the part that collided with the raycast?

Script:

local HRP = script.Parent:WaitForChild("HumanoidRootPart")

local settingS = RaycastParams.new()
settingS.IgnoreWater = false

while task.wait() do
	local ray = workspace:Raycast(HRP.Position, Vector3.new(0,-10,0), settingS)
	
	if ray then
		print(ray.Name)
	end
end
1 Like
ray.Instance.Name

Ray is a table which contains other information about the ray. Use ray.Instance to get the hitpart

6 Likes

Look at the Hit Detection section.

Sp does ray.Instance get whatever the ray hits and finds its Instance?

1 Like

Exactly. But be careful. Ray can be nil

1 Like

RaycastResult.Instance is a reference to the instance (object) the ray intersected. Be wary though, as warned here ‘RaycastResult’ is nil in cases where the ray intersects nothing.