GUI:WaitForChild("AccessoryEditor"):WaitForChild("Edit").MouseButton1Click:Connect(function()
local Handles = Instance.new("Handles", Player:WaitForChild("PlayerGui"))
Handles.Adornee = Accessory.Value:WaitForChild("Handle")
Handles.Style = Enum.HandlesStyle.Movement
Handles.MouseDrag:Connect(function(Face, Distance)
if Face == Enum.NormalId.Top then
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= CFrame.new(0, -Distance, 0)
elseif Face == Enum.NormalId.Bottom then
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= CFrame.new(0, Distance, 0)
elseif Face == Enum.NormalId.Front then
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= CFrame.new(-Distance, 0, 0)
elseif Face == Enum.NormalId.Back then
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= CFrame.new(Distance, 0, 0)
elseif Face == Enum.NormalId.Left then
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= CFrame.new(0, 0, Distance)
elseif Face == Enum.NormalId.Right then
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= CFrame.new(0, 0, -Distance)
end
end)
end)
Example:
Hopefully this small example is enough to show what’s wrong.
I’m attempting to make an accessory mover, but it’s not working for some reason or another. It is, but very, very poorly as shown in the example. Any help would be greatly appreciated, cheers!
I was having the same issues as you awhile ago but came across a solution that makes it work like studio’s draggers, plus cleaner being without the if-statements. Please let me know if there are any issues
local oldDelta = 0
local snap = 0.5 -- In studs
Handles.MouseDrag:Connect(function(face, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.125) >= snap then
delta = math.round(delta / snap) * snap
local direction = Vector3.fromNormalId(face)
local moveVector = Vector3.new(direction.X, direction.Y, direction.Z) * delta
-- Movement code here, ex:
-- Part.Position = Part.Position + moveVector
oldDelta = distance
end
end)
Handles.MouseButton1Up:Connect(function()
oldDelta = 0
end)
Well, it works fine, but there’s an issue where the hat is being moved in the completely wrong direction. Up is down, down is up, left is backwards?? Etc. Etc.
local oldDelta = 0
local snap = 0.5 -- In studs
GUI:WaitForChild("AccessoryEditor"):WaitForChild("Edit").MouseButton1Click:Connect(function()
local Handles = Instance.new("Handles", Player:WaitForChild("PlayerGui"))
Handles.Adornee = Accessory.Value:WaitForChild("Handle")
Handles.Style = Enum.HandlesStyle.Movement
GUI:WaitForChild("AccessoryEditor").Visible = false
Handles.MouseDrag:Connect(function(face, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.125) >= snap then
delta = math.round(delta / snap) * snap
local direction = Vector3.fromNormalId(face)
local moveVector = CFrame.new(Vector3.new(direction.X, direction.Y, direction.Z) * delta)
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= moveVector
oldDelta = distance
end
end)
Handles.MouseButton1Up:Connect(function()
oldDelta = 0
end)
end)
Alright I tested it and see the issue, I don’t have much experience with welds but simply inversing the Vector3 in the moveVector variable makes it work properly
local oldDelta = 0
local snap = 0.5 -- In studs
GUI:WaitForChild("AccessoryEditor"):WaitForChild("Edit").MouseButton1Click:Connect(function()
local Handles = Instance.new("Handles", Player:WaitForChild("PlayerGui"))
Handles.Adornee = Accessory.Value:WaitForChild("Handle")
Handles.Style = Enum.HandlesStyle.Movement
GUI:WaitForChild("AccessoryEditor").Visible = false
Handles.MouseDrag:Connect(function(face, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.125) >= snap then
delta = math.round(delta / snap) * snap
local direction = Vector3.fromNormalId(face)
local moveVector = CFrame.new(-Vector3.new(direction.X, direction.Y, direction.Z) * delta) -- this line right here
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= moveVector
oldDelta = distance
end
end)
Handles.MouseButton1Up:Connect(function()
oldDelta = 0
end)
end)
Yup, that works, thanks, but I still have an issue where the left/right and back/forward handles change places. Any ideas? I’m working with handles for the first time.
This might be because the accessory handle is rotated differently than how the handles expect, in that case I edited the code so you can correspond those handles to their correct directions, in the surfaceAxis table. The Y axis is likely fine like you said, but try swapping the Front/Back and Left/Right vectors to see if that works
local oldDelta = 0
local snap = 0.5 -- In studs
-- Currently how it's set up by default:
-- top = +Y, bottom = -Y, front = -Z, back = +Z, left = -X, right = +X
local surfaceAxis = {
[Enum.NormalId.Top] = Vector3.new(0, 1, 0),
[Enum.NormalId.Bottom] = Vector3.new(0, -1, 0),
[Enum.NormalId.Front] = Vector3.new(0, 0, -1),
[Enum.NormalId.Back] = Vector3.new(0, 0, 1),
[Enum.NormalId.Left] = Vector3.new(-1, 0, 0),
[Enum.NormalId.Right] = Vector3.new(1, 0, 0)
}
GUI:WaitForChild("AccessoryEditor"):WaitForChild("Edit").MouseButton1Click:Connect(function()
local Handles = Instance.new("Handles", Player:WaitForChild("PlayerGui"))
Handles.Adornee = Accessory.Value:WaitForChild("Handle")
Handles.Style = Enum.HandlesStyle.Movement
GUI:WaitForChild("AccessoryEditor").Visible = false
Handles.MouseDrag:Connect(function(face, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.125) >= snap then
delta = math.round(delta / snap) * snap
local direction = surfaceAxis[face]
local moveVector = CFrame.new(-direction * delta)
Accessory.Value:WaitForChild("Handle"):WaitForChild("AccessoryWeld").C0 *= moveVector
oldDelta = distance
end
end)
Handles.MouseButton1Up:Connect(function()
oldDelta = 0
end)
end)