I have a script that lets me teleport to the mouse position, raycasted from the character and mouse with a range of 80.
But, once the range is greater than 80, I get an error because the ray doesn’t exist that far.
How can I instead make it do something at the max range?
local Origin = player.Character.Head.Position
local Direction = Mouse.Hit.LookVector*80
local Rayparams = RaycastParams.new()
Rayparams.FilterDescendantsInstances = {player.Character}
Rayparams.FilterType = Enum.RaycastFilterType.Blacklist
local ray = Ray.new(Origin, Direction, Rayparams)
local Result = game.Workspace:Raycast(ray.Origin, ray.Direction, Rayparams)
if Result then
local raypos = CFrame.new(Result.Position)
HRP.CFrame = raypos