Changing the resize increment for a custom resize tool?

I made a resize tool for my filtering enabled game but I appear to be having problems with it.

when handling the handles I wanted to change the resize increment. I wanted it to change parts size by 0.5. but as I was tinkering with it I had no luck.

local tool = script.Parent
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
enabled = true
local selectionBox
local selectionLasso
local handles
local previousDistance
local originalpart
local buttonupconnection
local tempart

function onHandlesDown(normal)
	previousDistance = 0
end



function onHandlesDrag(normal, distance)
	if handles.Adornee then
--		print(handles.Adornee.ResizeIncrement)
		local delta = distance - previousDistance
		if math.abs(delta) >= handles.Adornee.ResizeIncrement then
			local sizeDelta = math.floor(delta / handles.Adornee.ResizeIncrement + 0.5) * handles.Adornee.ResizeIncrement
			if handles.Adornee:Resize(normal, sizeDelta) then
				previousDistance = distance
				--send changes to server
				buttonupconnection = mouse.Button1Up:connect(function()onButton1Up(mouse,handles.Adornee)end)
	--
			end
		end
	end
end




function onButton1Up(mouse,part)
	if part and script.Parent.Parent == plr.Character then
	local size = part.Size
	local cfr = part.CFrame
	script.Parent.PartChange:FireServer(originalpart,size,cfr)
	end
end




function onButton1Down(mouse)
	local findpart = game.ReplicatedStorage.BuildingParts:FindFirstChild(mouse.Target.Name)
	if tempart then
		tempart:Destroy()
		end
	if mouse.Target == nil or mouse.Target.Locked or not findpart then
		print("nil")
		selectionBox.Adornee = nil
		selectionLasso.Part = nil
		handles.Adornee = nil
	else
		print("not nil")
		originalpart = mouse.Target
		tempart = findpart:Clone()
		tempart.CanCollide = false
		tempart.Anchored = true
		tempart.Transparency = 0.6
		tempart.Size = originalpart.Size
		tempart.Parent = game.Workspace
		tempart.CFrame = originalpart.CFrame
		tempart.BrickColor = BrickColor.new("Lime green")
		selectionBox.Adornee = tempart
		selectionLasso.Part = tempart
		handles.Adornee = tempart
		handles.Faces = tempart.ResizeableFaces
	end
end




function onEquippedLocal(mouse)
	mouse.Button1Down:connect(function() onButton1Down(mouse) end)

	local character = script.Parent.Parent
	local player = game.Players:GetPlayerFromCharacter(character)
	
	selectionBox = Instance.new("SelectionBox")
	selectionBox.Color = BrickColor.Blue()
	selectionBox.Adornee = nil
	selectionBox.Parent = player.PlayerGui

	selectionLasso = Instance.new("SelectionPartLasso")
	selectionLasso.Name = "Model Delete Lasso"
	selectionLasso.Humanoid = character.Humanoid
	selectionLasso.Parent = game.workspace
	selectionLasso.Part = nil
	selectionLasso.Visible = true
	selectionLasso.archivable = false
	selectionLasso.Color = BrickColor.Red()

	handles = Instance.new("Handles")
	handles.Color = BrickColor.Blue()
	handles.Adornee = nil
	handles.MouseDrag:connect(onHandlesDrag)
	handles.MouseButton1Down:connect(onHandlesDown)
	handles.Parent = player.PlayerGui
end

function onUnequippedLocal()
	selectionBox:Destroy()
	selectionLasso:Destroy()
	handles:Destroy()
	if handles.Adornee then
		handles.Adornee:Destroy()
	end
	if buttonupconnection then
	buttonupconnection:Disconnect()
	end
end


tool.Equipped:connect(onEquippedLocal)
tool.Unequipped:connect(onUnequippedLocal)

the function onhandlesdrag is the main concern. I tried simply changing “sizedelta” to a number less than 1 such as 0.5, but that didn’t work. I tried changing the resize increment to a number such as 0.5, but no luck. I read up a post about the handles object. and it said that the resizeincrement can only be 1. is this true? and is there any way to change this?

test file.rbxl (21.2 KB)

1 Like

Just make your own ResizeIncrement value inside the script and use that one. onHandlesDrag() gets triggered anyways on every single move, even on 0.01 steps.

1 Like

Sadly, ResizeIncrement is a read-only value that is the minimum size :Resize() can do. You’re going to have to look into editing the size property, you might be able to find a module that is :Resize() but just unlocked?

ResizeIncrement is a read-only property

I thought about that, but how would I emulate resize as it uses the dragged handles to resize a specific face?

Again, you can make your own ResizeIncrement value inside the script so you don’t have to use the one provided by Handles. I did that myself back then too and it worked like butter. I just tried it again and it works like butter again.

local steps = 0.1 
-- This is your own ResizeIncrement, 
-- use this one instead of handles.Adornee.ResizeIncrement

even if I change the resize increment, I still have to perform the acual resize and keep in mind the whole point of using handles is to be able to resize the part while a portion of it is still in one place.

The only issue with this is that the ResizeIncrement property is a read-only value that is the minimum size you can use in :Resize(). If you go any lower then it, it will round it to 1. Please read this wiki post saying what ResizeIncrement is.

which means I need to replace :Resize() with something that “emulates it”.
I want to be able to stretch a part from were its currently positioned and for that I need the handles. but because resize/resize increment cannot resize 0.5 I have to make my own and I do not currently know how to do that with handles. is there a way I can resize the part in the direction I pull OR push the handle?

Save the initial CFrame and Size, and then on each resize you calculate the nearest step with your own step value and with that you apply the new size. (Don’t forget to reset the CFrame and Size before you apply the new size)

1 Like

Might as well throw in the code I just made with the solution above, fit to work with your code.

local originalCf, originalSize

function onHandlesDown(normal)
	previousDistance = 0
	
	originalCf = handles.Adornee.CFrame
	originalSize = handles.Adornee.Size
end

local steps = 0.1

local AxisSizeMultipliers = {
	[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);
}


local AxisPositioningMultipliers = {
	[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);
}
function onHandlesDrag(normal, distance)
	if handles.Adornee then
		distance = distance - (distance%steps)
		if previousDistance ~= distance then
			handles.Adornee.Size = originalSize + AxisSizeMultipliers[normal] * distance
			handles.Adornee.CFrame = originalCf + (AxisPositioningMultipliers[normal] * distance) / 2
			
			script.Parent.PartChange:FireServer(originalpart,handles.Adornee.Size, handles.Adornee.CFrame)
			previousDistance = distance
		end
	end
end

What I do is save the initial CFrame and Size, then calculate the new Size and Position with the original with the normal and the two new tables. It also now replicates to the server each time you resize it, but only if the size on your client actually changes.

4 Likes

looks good, thank you so much I was working on this problem all day and its a relieve to finally solve it.