FindPartOnRay issue

Hi, I’m trying to do hovercraft and in it I have a script that calculates the distance between the hovercraft and anything else (Parts, terrain, etc.) However, there is a problem because raycast does not work as I would like. It calculates the distance, but up to a certain distance or size of part. for example, if the part is too big, raycast ignores it, or if the part is too close or too far, it ignores it

This is my first time trying to do a script using raycast so I don’t really get it. I’m trying to learn it.

local PilotSeat = script:WaitForChild("PilotSeat").Value

local R = Ray.new(PilotSeat.Position, Vector3.new(0,-100,0))
local PartFound, Pos
local DistanceToGround

RunService.Heartbeat:Connect(function()
	
	PartFound, Pos = workspace:FindPartOnRay(R)
	
	if PartFound then
		print("Part: "..PartFound.Name)
		DistanceToGround = PilotSeat.Parent.Position.Y - PartFound.Position.Y
	end
	
	print("Distance: "..DistanceToGround)
	
end)

Blue part is called Z, and gray part is called X

Hey! Use WorldRoot:Raycast() for WorldRoot:FindPartOnRay() is deprecated. Im pretty rusty with raycasts also, and probably using WorldRoot:Raycast() should do the trick. Be sure to properly do it, as just changing FindPartOnRay() to Raycast() will not work. You have to make sure you use RaycastParams, and Raycasts return a RaycastResult. I really hope this helps!

Link to Raycast API:

1 Like

Thanks!! I have read the stuff You sent me, tried to do what it said and it worked! The script now calculates the height between hovercraft and the instance normally. Thank You for help!

1 Like