local V=game:GetService("\082\117\110\083\101\114\118\105\099\101")local N=game:GetService("\085\115\101\114\073\110\112\117\116\083\101\114\118\105\099\101")local q=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local E=Instance.new("\068\114\097\103\103\101\114")local I=script.Parent local m=Instance.new("\083\101\108\101\099\116\105\111\110\066\111\120")m.Parent=I m.Transparency=1 local M=I.Name local w=q:WaitForChild("\068\114\097\103\103\101\114\083\101\114\118\105\099\101")local a=w:WaitForChild("\068\114\097\103\103\101\114\071\097\116\101\119\097\121")local p=w:WaitForChild("\083\117\098\109\105\116\085\112\100\097\116\101")local C={}local function o(V)if C[V.KeyCode.Name]then C[V.KeyCode.Name]=nil end end local function H(V)if N:IsKeyDown(V)and not C[V]then C[V]=true return true end return false end N.InputEnded:Connect(o)local t={_KGameTool={Icon="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\048\052\056\049\050\057\054\053\051",HoverColor=Color3.fromRGB(25,153,255),Cursors={Idle="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\048\048\048\048\048\048";Hover="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\068\114\097\103\067\117\114\115\111\114\046\112\110\103";Grab="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\071\114\097\098\082\111\116\097\116\101\067\117\114\115\111\114\046\112\110\103"}};_KClone={Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\067\108\111\110\101\046\112\110\103",HoverColor=Color3.fromRGB(25,153,255);Cursors={Idle="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\067\108\111\110\101\067\117\114\115\111\114\046\112\110\103",Hover="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\048\052\056\049\051\054\056\051\048",Grab="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\071\114\097\098\082\111\116\097\116\101\067\117\114\115\111\114\046\112\110\103"}};_KHammer={Icon="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\072\097\109\109\101\114\046\112\110\103";HoverColor=Color3.new(1,.5,0),CanShowWithHover=true;Cursors={Idle="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\072\097\109\109\101\114\067\117\114\115\111\114\046\112\110\103";Hover="\114\098\120\097\115\115\101\116\058\047\047\116\101\120\116\117\114\101\115\047\072\097\109\109\101\114\079\118\101\114\067\117\114\115\111\114\046\112\110\103"}}}if not t[M]then error("\066\097\100 \109\111\100\101 \115\112\101\099\105\102\105\099\097\116\105\111\110\058 "..M)end local function f(V)return t[M].Cursors[V]end I.TextureId=t[M].Icon m.Color3=t[M].HoverColor if t[M].CanShowWithHover then m.Transparency=0 end local Z local i local X=false local G=false local function c()if not X and Z then local V=Z.Target if V and not V.Locked then m.Adornee=V Z.Icon=f("\072\111\118\101\114")return end m.Adornee=nil Z.Icon=f("\073\100\108\101")end end local function B(N)if M=="\095\075\072\097\109\109\101\114"then a:InvokeServer("\082\101\113\117\101\115\116\068\101\108\101\116\101",N)return end local q=(N.CFrame:toObjectSpace(Z.Hit)).p local I,w,C=a:InvokeServer("\071\101\116\075\101\121",N,M=="\095\075\067\108\111\110\101")if I and C then m.Adornee=C m.Transparency=0 i=w Z.Icon=f("\071\114\097\098")E:MouseDown(C,q,{C})X=true local N=0 while X do local q=tick()E:MouseMove(Z.UnitRay)local I=m.Adornee if I and i then if H("\082")then E:AxisRotate("\090")elseif H("\084")then E:AxisRotate("\088")end if q-N>.03 then p:FireServer(i,I.CFrame)N=q end end V.RenderStepped:Wait()end m.Transparency=1 a:InvokeServer("\067\108\101\097\114\075\101\121",w)i=nil end end local function d()if not G then G=true local V=m.Adornee if V and not X then B(V)end G=false end end local function F()if X then X=false E:MouseUp()end end local K={}local function O(V)for V,N in pairs(V)do local q=V:Connect(N)table.insert(K,q)end end local function j()while#K>0 do local V=table.remove(K)V:Disconnect()end end local function g(V)Z=V O({[Z.Button1Down]=d;[Z.Button1Up]=F;[Z.Idle]=c})end local function n()F()j()m.Adornee=nil if Z then Z.Icon=""Z=nil end end I.Equipped:Connect(g)I.Unequipped:Connect(n)
---------------------------------------------------------------------------------------------------------------------------
-- @CloneTrooper1019, 2017 <3
-- DraggerScript.lua
-- This script emulates the behavior of Roblox's classic build tools.
---------------------------------------------------------------------------------------------------------------------------
-- Initial declarations
---------------------------------------------------------------------------------------------------------------------------

local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Dragger = Instance.new("Dragger")

local tool = script.Parent

local selection = Instance.new("SelectionBox")
selection.Parent = tool
selection.Transparency = 1

local mode = tool.Name
local draggerService = ReplicatedStorage:WaitForChild("DraggerService")
local gateway = draggerService:WaitForChild("DraggerGateway")
local submitUpdate = draggerService:WaitForChild("SubmitUpdate")

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Keys
----------------------------------------------------------------------------------------------------------------------------------------------------------------

local keyLocks = {}

local function onInputEnded(input)
	if keyLocks[input.KeyCode.Name] then
		keyLocks[input.KeyCode.Name] = nil
	end
end

local function isKeyDown(key)
	if UserInputService:IsKeyDown(key) and not keyLocks[key] then
		keyLocks[key] = true
		return true
	end
	return false
end

UserInputService.InputEnded:Connect(onInputEnded)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Tool Style
----------------------------------------------------------------------------------------------------------------------------------------------------------------

local style =
{
	_KGameTool =
	{
		Icon = "rbxassetid://1048129653";
		HoverColor = Color3.fromRGB(25,153,255);
		Cursors =
		{
			Idle = "rbxassetid://1000000";
			Hover = "rbxasset://textures/DragCursor.png";
			Grab = "rbxasset://textures/GrabRotateCursor.png";
		};
	};
	_KClone =
	{
		Icon = "rbxasset://textures/Clone.png";
		HoverColor = Color3.fromRGB(25,153,255);
		Cursors =
		{
			Idle = "rbxasset://textures/CloneCursor.png";
			Hover = "rbxassetid://1048136830";
			Grab = "rbxasset://textures/GrabRotateCursor.png";
		}
	};
	_KHammer =
	{
		Icon = "rbxasset://textures/Hammer.png";
		HoverColor = Color3.new(1,0.5,0);
		CanShowWithHover = true;
		Cursors =
		{
			Idle = "rbxasset://textures/HammerCursor.png";
			Hover = "rbxasset://textures/HammerOverCursor.png";
		}
	}
}

if not style[mode] then
	error("Bad mode specification: " .. mode)
end

local function getIcon(iconType)
	return style[mode].Cursors[iconType]
end

tool.TextureId = style[mode].Icon
selection.Color3 = style[mode].HoverColor
if style[mode].CanShowWithHover then
	selection.Transparency = 0
end

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Dragger
----------------------------------------------------------------------------------------------------------------------------------------------------------------

local mouse
local currentKey
local down = false
local debounce = false

local function onIdle()
	if (not down) and mouse then
		local mousePart = mouse.Target
		if mousePart and not mousePart.Locked then
			selection.Adornee = mousePart
			mouse.Icon = getIcon("Hover")
			return
		end
		selection.Adornee = nil
		mouse.Icon = getIcon("Idle")
	end
end

local function startDraggerAction(mPart)
	if mode == "_KHammer" then
		gateway:InvokeServer("RequestDelete",mPart)
		return
	end

	local pointOnMousePart = mPart.CFrame:toObjectSpace(mouse.Hit).p
	local canDrag,dragKey,mousePart = gateway:InvokeServer("GetKey",mPart,mode == "_KClone")

	if canDrag and mousePart then
		selection.Adornee = mousePart
		selection.Transparency = 0
		currentKey = dragKey
		mouse.Icon = getIcon("Grab")
		Dragger:MouseDown(mousePart,pointOnMousePart,{mousePart})
		down = true

		local lastSubmit = 0
		while down do
			local now = tick()
			Dragger:MouseMove(mouse.UnitRay)

			local selected = selection.Adornee
			if selected and currentKey then
				if isKeyDown('R') then
					Dragger:AxisRotate('Z')
				elseif isKeyDown('T') then
					Dragger:AxisRotate('X')
				end
				if now - lastSubmit > 0.03 then
					submitUpdate:FireServer(currentKey, selected.CFrame)
					lastSubmit = now
				end
			end

			RunService.RenderStepped:Wait()
		end

		selection.Transparency = 1
		gateway:InvokeServer("ClearKey",dragKey)
		currentKey = nil
	end
end

local function onButton1Down()
	if not debounce then
		debounce = true
		local mousePart = selection.Adornee
		if mousePart and not down then
			startDraggerAction(mousePart)
		end
		debounce = false
	end
end

local function onButton1Up()
	if down then
		down = false
		Dragger:MouseUp()
	end
end

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Connections
----------------------------------------------------------------------------------------------------------------------------------------------------------------

local connections = {}

local function pushConnections(connectionData)
	for event,func in pairs(connectionData) do
		local connection = event:Connect(func)
		table.insert(connections,connection)
	end
end

local function popConnections()
	while #connections > 0 do
		local connection = table.remove(connections)
		connection:Disconnect()
	end
end

----------------------------------------------------------------------------------------------------------------------------------------------------------------
-- Tool
----------------------------------------------------------------------------------------------------------------------------------------------------------------

local function onEquipped(newMouse)
	mouse = newMouse
	pushConnections
	{
		[mouse.Button1Down] = onButton1Down;
		[mouse.Button1Up]   = onButton1Up;
		[mouse.Idle]        = onIdle;
	}
end

local function onUnequipped()
	onButton1Up()
	popConnections()
	selection.Adornee = nil
	if mouse then
		mouse.Icon = ""
		mouse = nil
	end
end

tool.Equipped:Connect(onEquipped)
tool.Unequipped:Connect(onUnequipped)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
