You can try something like this, first of all you should calculate the distance between the CuffPart and the mouse position. If the distance exceeds a certain threshold, you can prevent the CuffPart from moving beyond that limit. Try this code and let me know if it worked.
local distancethreshold = 50
Remotes["Stepped."].OnServerEvent:Connect(function(Player, MousePosition: Vector3)
local currentPosition = CuffPart.Position
local distance = (currentPosition - MousePosition).Magnitude
if distance > distancethreshold then
local direction = (MousePosition - currentPosition).Unit
MousePosition = currentPosition + direction * distancethreshold
end
CuffPart.Position = MousePosition
end)
Well, I Am making a cuff, The cuffed person goes to the CuffPart, Which is why I am moving it, I Wish the player be able to move the CuffPart in the specific range of movement.
local maxDistance = 10 -- Define the maximum distance CuffPart can move from the player's position
Remotes["Stepped."].OnServerEvent:Connect(function(Player, MousePosition: Vector3)
-- Get the player's position (assuming the player has a character and a primary part)
local playerPosition = Player.Character.HumanoidRootPart.Position
-- Calculate the direction and distance from the player to the mouse position
local direction = (MousePosition - playerPosition)
local distance = direction.Magnitude
-- Clamp the distance to the maximum allowed distance
if distance > maxDistance then
direction = direction.Unit * maxDistance
end
-- Set the new position of the CuffPart
CuffPart.Position = playerPosition + direction
end
end)