I adorneed handles to a part then put the handles in starter GUI. I want to know how to actually make the handles resize or move the part it is adorneed to.
This seems like a very unpopular topic so I couldn’t find the answer by googling it.
I adorneed handles to a part then put the handles in starter GUI. I want to know how to actually make the handles resize or move the part it is adorneed to.
This seems like a very unpopular topic so I couldn’t find the answer by googling it.
Went into studio to try and make something for this and here’s how you can resize an even amount alongside an axis:
local handles = script.Parent
local deltaSum = 0
-- Reset the resize value once the mouse is back up
handles.MouseButton1Up:Connect(function()
deltaSum = 0
end)
handles.MouseDrag:Connect(function(normalId, delta)
-- The newDelta is the current delta - the previous delta if the current delta is positive or
-- the current delta + the previous delta if the current delta is negative
local newDelta = (delta > 0 and (delta - deltaSum) or (delta + deltaSum))
-- Create a Vector3 on the respective axis
local vector = Vector3.new()
if (normalId == Enum.NormalId.Top or normalId == Enum.NormalId.Bottom) then
-- I found 2 to be a nice resize factor
vector = Vector3.new(0, newDelta * 2, 0)
-- Just repeat for the left & right axis and the front & back axis
end
-- Apply the change to deltaSum
deltaSum += newDelta
-- Apply the change to the actual adornee
handles.Adornee.Size += vector
end)
Sorry, I tried that and it didn’t work, but it didn’t return any errors. I used a local script inside of the handles for it.
Edit: Oh nevermind it did work, but only for the top and bottom part. Also it is very glitchy and buggy, I think it needs a different script.
What do you mean by glitchy and buggy?
I have an old script that… might work. You could try it out.
local handle = script.Parent
local oldDelta = 0
local snap = 2
local smallestSize = 1
local surfaceAxis = {
[Enum.NormalId.Top] = 'Y',
[Enum.NormalId.Bottom] = 'Y',
[Enum.NormalId.Front] = 'Z',
[Enum.NormalId.Back] = 'Z',
[Enum.NormalId.Left] = 'X',
[Enum.NormalId.Right] = 'X'
}
handle.MouseDrag:Connect(function(normal, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.1) >= snap then
delta = math.round(delta / snap) * snap
if handle.Adornee.Size[surfaceAxis[normal]] + delta > smallestSize and handle.Adornee:Resize(normal, delta) then
oldDelta = distance
end
end
end)
It moved the top and bottom at the same time, also it kept getting super thing and super large constantly.
Notice: The script uses Roblox’s :Resize() function. This means that it can’t go through parts so it could get caught on small parts.
I’m guessing the best way to fix that is this:
local handle = script.Parent
local oldDelta = 0
local snap = 2
local smallestSize = 1
local surfaceAxis = {
[Enum.NormalId.Top] = 'Y',
[Enum.NormalId.Bottom] = 'Y',
[Enum.NormalId.Front] = 'Z',
[Enum.NormalId.Back] = 'Z',
[Enum.NormalId.Left] = 'X',
[Enum.NormalId.Right] = 'X'
}
handle.MouseDrag:Connect(function(normal, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.1) >= snap then
delta = math.round(delta / snap) * snap
local endSize = handle.Adornee.Size[surfaceAxis[normal]] + delta
if endSize > smallestSize then
handle.Adornee.Size = endSize
oldDelta = distance
end
end
end)
One weird thing about the script you used, is whenever I click on a handle it resets the size back to normal
That returned error: Players.RichPerson03return.PlayerGui.Handles.LocalScript:23: invalid argument #3 (Vector3 expected, got number)
Edit: vector3 has 3 number values in it, so I guess you gotta detect which axis to resize
So, how did you set your handles up? I can’t seem to figure out how to test the script that I made (lol) Found out.
Anywho, to fix that you should use (pending)
I tried using this:
local handle = script.Parent
local oldDelta = 0
local snap = 2
local smallestSize = 1
local surfaceAxis = {
[Enum.NormalId.Top] = 'Y',
[Enum.NormalId.Bottom] = 'Y',
[Enum.NormalId.Front] = 'Z',
[Enum.NormalId.Back] = 'Z',
[Enum.NormalId.Left] = 'X',
[Enum.NormalId.Right] = 'X'
}
handle.MouseDrag:Connect(function(normal, distance)
local delta = distance - oldDelta
if math.abs(delta * 1.1) >= snap then
delta = math.round(delta / snap) * snap
local endSize = handle.Adornee.Size[surfaceAxis[normal]] + delta
if endSize > smallestSize then
if normal == Enum.NormalId.Front or Enum.NormalId.Back then
handle.Adornee.Size = Vector3.new(delta,delta,endSize)
elseif normal == Enum.NormalId.Left or Enum.NormalId.Right then
handle.Adornee.Size = Vector3.new(endSize,delta,delta)
elseif normal == Enum.NormalId.Top or Enum.NormalId.Bottom then
handle.Adornee.Size = Vector3.new(delta,endSize,delta)
end
oldDelta = distance
end
end
end)
But then it didn’t do anything.
Edit: It did do something. I just had the script disabled bruh. It had weird results though.
robloxapp-20210822-0008582.wmv (1.2 MB)
Edit I fixed the script kinda using this:
if endSize > smallestSize then
if normal == Enum.NormalId.Front or Enum.NormalId.Back then
handle.Adornee.Size = Vector3.new(handle.Adornee.Size.X,handle.Adornee.Size.Y,endSize)
elseif normal == Enum.NormalId.Left or Enum.NormalId.Right then
handle.Adornee.Size = Vector3.new(endSize,handle.Adornee.Size.Y,handle.Adornee.Size.Z)
elseif normal == Enum.NormalId.Top or Enum.NormalId.Bottom then
handle.Adornee.Size = Vector3.new(handle.Adornee.Size.X,endSize,handle.Adornee.Size.Z)
end
oldDelta = distance
end
It still acted weird though
Solved it:
local handle = script.Parent
handle.Adornee = workspace.Part
local oldDelta = 0
local snap = 2
local smallestSize = 1
local surfaceAxis = {
[Enum.NormalId.Top] = 'Y',
[Enum.NormalId.Bottom] = 'Y',
[Enum.NormalId.Front] = 'Z',
[Enum.NormalId.Back] = 'Z',
[Enum.NormalId.Left] = 'X',
[Enum.NormalId.Right] = 'X'
}
handle.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 size = Vector3.new(math.abs(direction.X), math.abs(direction.Y), math.abs(direction.Z))
local endSize = handle.Adornee.Size + size * delta
if endSize[surfaceAxis[face]] > smallestSize then
handle.Adornee.Size = endSize
handle.Adornee:PivotTo(handle.Adornee.CFrame * CFrame.new(direction / 2 * delta))
oldDelta = distance
end
end
end)
handle.MouseButton1Up:Connect(function()
oldDelta = 0
end)