How do I teleport to max range?

Hey, so I have max range (100) in a variable, I’m trying to make it so that if the user tries to teleport within that range, it just teleports them and if they try to teleport and the range where they are trying to teleport is >100 then it will just teleport them to the max range, in the direction they put their mouse in. Here is my script, any ideas?

local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")

local Modules = ServerScriptService:WaitForChild("Modules")

local Remotes = ReplicatedStorage:WaitForChild("Remotes")
local TeleportRemote = Remotes.RequestTeleport
local Utils = require(Modules:WaitForChild("Utils"))
local CharacterAbilities = require(Modules:WaitForChild("CharacterAbilities"))

TeleportRemote.OnServerEvent:Connect(function(plr, mouse)
	local Data = Utils.GetData(plr)
	if not Data then return plr:Kick(Utils.Error("No data.")) end
	local PlayerChar = Data.Character.Value
	if PlayerChar ~= "None" then
		local plrchar = plr.Character
		local Head = plrchar.Head
		local TPRange = CharacterAbilities[PlayerChar].TPRange
		local Magnitude = (Head.Position - mouse).Magnitude
		local HumanoidRootPart = plrchar.HumanoidRootPart
		if Data.lockedOnto.Value ~= "None" then
			local playerlocked = Data.lockedOnto.Value
			local Players = game:GetService("Players")
			local playertar = Players:FindFirstChild(playerlocked)
			local targetchar = playertar.Character
			local targethead = targetchar.Head
			local Magnitude2 = (Head.Position - targethead.Position).Magnitude
			if TPRange > Magnitude2 then
				local OFFSET = 4
				targetchar:WaitForChild("HumanoidRootPart").CFrame = plrchar:WaitForChild("HumanoidRootPart").CFrame * CFrame.new(0, 0, -OFFSET)
			end
		elseif TPRange > Magnitude then
			HumanoidRootPart.Position = mouse
		else
			print("insufficient tprange")
		end
	end

end)```

after this add another condition

elseif Magnitude > 0 then
    HumanoidRootPart.Position = (mouse - Head.Position).Unit * TPRange + Head.Position

don’t send mouse itself, send a proprety

TeleportRemote.OnServerEvent:Connect(function(plr, mousepos, mousetarget)