You can get the direction then multiply it by your range variable to limit how far away the part is.
local direction = (hrp.Position - part.Position).Unit -- Might be backwards, swap hrp & pos if they are
local finalPosition = hrp.Position + direction * range
And I would suggest using @DrKittyWaffles method of getting the range variable via math.min.
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local range = math.min(50, (script.Parent.HumanoidRootPart.Position - FixPart.Position).Magnitude)
game:GetService('RunService').RenderStepped:Connect(function()
mouse.TargetFilter = c
local pos = mouse.Hit.Position
FixPart.CFrame = CFrame.new(pos) * CFrame.new(0,math.floor,0)
end)
You’ll want range inside the RenderStepped event so it updates
assuming you want to have the part go from the hrp to the mouse, you’ll need something like this
-- inside RenderStepped
local range = math.min(50, (hrp.Position - pos).Magnitude)
local direction = (hrp.Position - pos).Unit -- Might be backwards, swap hrp & pos if they are
FixPart.CFrame = CFrame.new(hrp.Position + direction * range)