Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Tool = script.Parent
- local selectionBox
- local currentSelection
- local dragger
- local lockTime = 0
- local cloneTool = true
- local cloneSound
- local antiAbuse = true
- local antiAbuseTime = 0.5
- local isE = false
- local mouse
- local debounce = false
- local ev = {}
- function canSelectObject(part)
- return part and part:IsA("BasePart") and (not (part.Locked))
- end
- function startDrag(mousePart, hitPoint, collection)
- selectionBox.Adornee = mousePart
- dragger = Instance.new("Dragger")
- pcall(function() dragger:MouseDown(mousePart, hitPoint, collection) end)
- end
- function onMouseDown(mouse)
- local part = mouse.Target
- if canSelectObject(part) then
- local hitPoint = part.CFrame:toObjectSpace(CFrame.new(mouse.Hit.p)).p
- if trySelection(part) then
- if cloneTool then
- if debounce == false then
- debounce = true
- local cloned = part:clone()
- cloned.Parent = game.Workspace
- cloned.Position = part.Position + Vector3.new(0, 0.4, 0)
- cloneSound:Play()
- Spawn(function()
- if antiAbuse then
- wait(antiAbuseTime)
- end
- debounce = false
- end)
- if trySelection(cloned) then
- mouse.Icon = "rbxasset://textures/DragCursor.png"
- startDrag(cloned, hitPoint, {cloned})
- return
- end
- end
- else --dragtool
- mouse.Icon = "rbxasset://textures/DragCursor.png"
- startDrag(part, hitPoint, {part})
- return
- end
- end
- end
- --Clear the selection if we weren't able to lock succesfullu
- onMouseUp(mouse)
- end
- function onMouseUp(mouse)
- if dragger ~= nil then
- pcall(function() dragger:MouseUp() end)
- dragger = nil
- clearSelection()
- onMouseMove(mouse)
- end
- end
- function trySelection(part)
- if canSelectObject(part) then
- return setSelection(part)
- else
- clearSelection()
- return false
- end
- end
- function onKeyDown(key)
- if dragger ~= nil then
- if key == 'R' or key == 'r' then
- dragger:AxisRotate(Enum.Axis.Y)
- elseif key == 'T' or key == 't' then
- dragger:AxisRotate(Enum.Axis.Z)
- end
- end
- end
- local alreadyMoving
- function onMouseMove(mouse)
- if alreadyMoving then
- return
- end
- alreadyMoving = true
- if dragger ~= nil then
- mouse.Icon = "rbxasset://textures/GrabRotateCursor.png"
- --Maintain the lock
- if time() - lockTime > 3 then
- Instance.Lock(currentSelection)
- lockTime = time()
- end
- --Then drag
- pcall(function() dragger:MouseMove(mouse.UnitRay) end)
- else
- if trySelection(mouse.Target) then
- mouse.Icon = (cloneTool and "rbxasset://textures/CloneOverCursor.png") or "rbxasset://textures/DragCursor.png"
- else
- mouse.Icon = (cloneTool and "rbxasset://textures/CloneCursor.png") or "rbxasset://textures/ArrowFarCursor.png"
- end
- end
- alreadyMoving = false
- end
- function setSelection(partOrModel)
- if partOrModel ~= currentSelection then
- clearSelection()
- if Instance.Lock(partOrModel) then
- lockTime = time()
- currentSelection = partOrModel
- return true
- end
- else
- if currentSelection ~= nil then
- if time() - lockTime > 2 then
- --Maintain the lock
- if not(Instance.Lock(currentSelection)) then
- --we lost the lock
- clearSelection()
- return false
- else
- lockTime = time()
- return true
- end
- else
- return true
- end
- end
- end
- return false
- end
- function clearSelection()
- if currentSelection ~= nil then
- Instance.Unlock(currentSelection)
- end
- currentSelection = nil
- selectionBox.Adornee = nil
- end
- function onEquippedLocal()
- if not isE then --roblox bugged tools somehow
- isE = true
- else
- return
- end
- local player = game.Players.LocalPlayer
- local character = player.Character
- mouse = player:GetMouse()
- table.insert(ev, mouse.Button1Down:connect(function() onMouseDown(mouse) end))
- table.insert(ev, mouse.Button1Up:connect(function() onMouseUp(mouse) end))
- table.insert(ev, mouse.Move:connect(function() onMouseMove(mouse) end))
- table.insert(ev, mouse.KeyDown:connect(function(string) onKeyDown(string) end))
- cloneSound = Instance.new("Sound")
- cloneSound.SoundId = "rbxasset://sounds/electronicpingshort.wav"
- cloneSound.Parent = Tool
- selectionBox = Instance.new("SelectionBox")
- selectionBox.Name = "Model Delete Selection"
- selectionBox.Color3 = Color3.new(25/255, 153/255, 255/255)
- selectionBox.LineThickness = 0.02
- selectionBox.Adornee = nil
- selectionBox.Parent = player.PlayerGui
- alreadyMoving = false
- Spawn(function()
- wait()
- onMouseMove(mouse)
- end)
- end
- function onUnequippedLocal()
- isE = false
- for i, v in pairs(ev) do
- v:disconnect()
- end
- mouse.Icon = ""
- ev = {}
- clearSelection()
- selectionBox:Remove()
- cloneSound:Remove()
- end
- Tool.Equipped:connect(onEquippedLocal)
- Tool.Unequipped:connect(onUnequippedLocal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement