I should have known I could not satisfy you with that pseudocode. The first thing you should know, yes the max distance for rays is 5000. The second thing FindPartOnRay is deprecated. WorldRoot | Documentation - Roblox Creator Hub
The way you would double the length of a ray over its max is to make another ray if it doesn’t encounter anything with the first cast. However, in order to do that you need to get to the end of the ray, which you can do with this:
local endOfRay = (CFrame.new(rayOrigin) * CFrame.new(Vector3.new(0,0,0), direction) * CFrame.new(0,0,-5000)).Position
To break this down, first, we make a frame with no direction at the origin, we then add on a CFrame that has the rotation pointing in the same direction, finally, we go -5000 studs on the z-axis to get to the end of the ray.
To wholly satisfy you, I actually tested my code this time and have made this solution:
local players = game:GetService("Players")
local uis = game:GetService("UserInputService")
local plr = players.LocalPlayer
local maxDist = 60000
local debounce = false
local function createRay(start, direction, char)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {plr.Character}
raycastParams.IgnoreWater = false
return workspace:Raycast(start, direction * 5000, raycastParams)
end
uis.InputBegan:Connect(function(inp, gpe)
if gpe then return end
if inp.KeyCode == Enum.KeyCode.F then
if debounce then return end
debounce = true
local mouse = plr:GetMouse()
local originPos = plr.Character.PrimaryPart.CFrame.Position
local startPos = originPos
local direction = (mouse.Hit.Position - originPos).Unit
print(direction)
local result = createRay(startPos, direction, plr.Character)
local reachedDist = 5000
while not result and not (maxDist < reachedDist) do
reachedDist += 5000
local startPos = (CFrame.new(startPos) * CFrame.new(Vector3.new(0,0,0), direction) * CFrame.new(0,0,-5000)).Position
result = createRay(startPos, direction, plr.Character)
end
if result then
print("Distance from origin:", (result.Position - originPos).Magnitude)
end
debounce = false
end
end)
This example may not be exactly what you want but I hope you can infer what to do using it. I noticed in your example code you provided you wanted to use the RangefinderPart and it’s look vector, that is fine just use that for the originPos and the look vector for the distance, be sure to add the rangefinder part to the ignore list in the createRay function. I hope this helps, let me know if you need anything more.