I'm trying to make a ray coming from the player's torso (humanoidrootpart for r15 support), going forward in the direction it's facing to find how far the part that's closest in-front of it is.
I made this script but for some reason it doesn't properly do what I want. (local)
game:GetService("RunService").RenderStepped:connect(function()
local ray = Ray.new(plr.Character.HumanoidRootPart.Position, plr.Character.HumanoidRootPart.CFrame.lookVector)
local part, position = workspace:FindPartOnRay(ray, plr.Character, false, true)
local distance = (plr.Character.HumanoidRootPart.Position - position).magnitude
print(distance)
end
Anyone have any idea what the problem is?

1 comment
Thank you!