Hello! How can I make a resize tool and move tool. Here’s the code I have for both.
Also, how can I make the increment 1 stud?
Resize tool:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local handles = tool:WaitForChild("Handles")
local draggingInProgress = false
handles.Parent = player.PlayerGui
tool.Activated:Connect(function()
handles.Adornee = mouse.Target
_G.PartSelected = mouse.Target
end)
handles.MouseButton1Down:Connect(function()
local dragC, mouseUpC
local prevDist = 0 --The distance from last time handles.MouseDrag fired
dragC = handles.MouseDrag:Connect(function(face, distance)
local deltaDist = (distance - prevDist) --How far the handle was dragged
local resizeDir = Vector3.FromNormalId(face)
if resizeDir.X == -1 or resizeDir.Y == -1 or resizeDir.Z == -1 then
handles.Adornee.Size += -1 * resizeDir * deltaDist
else
handles.Adornee.Size += resizeDir * deltaDist
end
handles.Adornee.Position += resizeDir * deltaDist / 2
prevDist = distance --Update for next time handle is dragged
end)
mouseUpC = handles.MouseButton1Up:Connect(function()
dragC:Disconnect()
mouseUpC:Disconnect()
end)
end)
Move tool:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local tool = script.Parent
local handles = tool:WaitForChild("Handles")
local draggingInProgress = false
handles.Parent = player.PlayerGui
tool.Activated:Connect(function()
handles.Adornee = mouse.Target
_G.PartSelected = mouse.Target
end)
handles.MouseButton1Down:Connect(function()
local dragC, mouseUpC
local prevDist = 0 --The distance from last time handles.MouseDrag fired
dragC = handles.MouseDrag:Connect(function(face, distance)
local deltaDist = (distance - prevDist) --How far the handle was dragged
local resizeDir = Vector3.FromNormalId(face)
if resizeDir.X == -1 or resizeDir.Y == -1 or resizeDir.Z == -1 then
handles.Adornee.Position += -1 * resizeDir * deltaDist
else
handles.Adornee.Position += resizeDir * deltaDist
end
handles.Adornee.Position += resizeDir * deltaDist / 2
prevDist = distance --Update for next time handle is dragged
end)
mouseUpC = handles.MouseButton1Up:Connect(function()
dragC:Disconnect()
mouseUpC:Disconnect()
end)
end)
Note: I got the code from @ThanksRoBama here
Video of the weird behavior of the move tool: