How to perfectly recreate studio's part dragging system?

  1. What do you want to achieve? Keep it simple and clear!
    A part dragging script with dragging exactly like in Roblox Studio.

  2. What is the issue? Include screenshots / videos if possible!
    My part dragging script doesn’t exactly work like in Roblox Studio.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried looking into the scripts of f3x building tools, because their dragging system is the same as in Roblox Studio, but the code was too hard for me to understand.

Heres the main part in my current part dragging sytem:

-- some functions used in the main loop
function rayCast(params)
	local mousePos = UserInputService:GetMouseLocation()
	local mouseRay = camera:ViewportPointToRay(mousePos.X, mousePos.Y)
	local rayCastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 2048, params)
	return rayCastResult

function roundPos(position, roundTo)
	return*roundTo, math.round(position.Y/roundTo)*roundTo, math.round(position.Z/roundTo)*roundTo)

-- some variables for the main loop
local offset
local startPos = part.Position
-- main loop		
local connection = RunService.RenderStepped:Connect(function()			
	local params =
	params.FilterType = Enum.RaycastFilterType.Exclude
	params.FilterDescendantsInstances = {part, player.Character, workspace.SpawnLocation}
	rayCastResult = rayCast(params)
	if rayCastResult then
		part.Position = rayCastResult.Position +, part.Size.Y/2, 0)
		part.Position = roundPos(part.Position, 1)
		if not offset then
			offset = startPos - part.Position
			offset =, 0, offset.Z)
		part.Position += offset
while true do
	if UserInputService.InputEnded:Wait().UserInputType == Enum.UserInputType.MouseButton1 then break end

If there are any uncertainties about the code please let me know and I’ll try to explain it as well as I can.

If you will be able to write a part dragging script that feels just like part dragging in Roblox Studio in the similar format as the script above I will be really grateful. I also might give you a little something😏