Moving a part by dragging handles

I’m trying to move a part with handles. I’ve noticed that handles are not very well documented or discussed on the DevForum, which makes it tricky for people like me who need to work with them.

I tried writing this script, but it is really buggy, poorly designed, and almost unusable for a regular player. Does anyone know how to fix the dragging or limit the speed at which the distance changes?

runService.RenderStepped:Connect(function()
	if currentArrow and not currentArrowConnection then
		currentArrowConnection = currentArrow.MouseDrag:Connect(function(face, distance)
			local faceName
			local newPos

			if face == Enum.NormalId.Back then
				newPos = currentCopy.Position + Vector3.new(0,0,distance)
				currentCopy.Position = newPos
			elseif face == Enum.NormalId.Bottom then
				newPos = currentCopy.Position + Vector3.new(0,-distance,0)
				currentCopy.Position = newPos
			elseif face == Enum.NormalId.Top then
				newPos = currentCopy.Position + Vector3.new(0,distance,0)
				currentCopy.Position = newPos
			elseif face == Enum.NormalId.Front then
				newPos = currentCopy.Position + Vector3.new(0,0,-distance)
				currentCopy.Position = newPos
			elseif face == Enum.NormalId.Left then
				newPos = currentCopy.Position + Vector3.new(-distance,0,0)
				currentCopy.Position = newPos
			elseif face == Enum.NormalId.Right then
				newPos = currentCopy.Position + Vector3.new(distance,0,0)
				currentCopy.Position = newPos
			end
			print(distance)
		end)
	end
end)

I made a video to show you how the part behaves when im dragging the handles

what im trying to achieve:

Using handles is a lot simpler than that.

Just save the initial CFrame of the part, then use the handles.MouseDrag event to offset the part’s CFrame from the initial CFrame when the drag started.

local handles = script.Parent:WaitForChild('Handles')

local adornee = handles.Adornee

local initialPartCFrame

handles.MouseButton1Down:Connect(function(face: Enum.NormalId)
	initialPartCFrame = adornee.CFrame -- save the part's CFrame
end)

handles.MouseDrag:Connect(function(face: Enum.NormalId, distance: number)
	adornee.CFrame = initialPartCFrame * CFrame.new(Vector3.fromNormalId(face) * distance) -- move the part `distance` studs on the local axis
end)

3 Likes

Thank you SO much!! I’ve had this problem for MONTHS now and it has been finally fixed bro thank you

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.