Making a scaling system and it scales from both sides (How to implement increment)

I am making a game like Mashables. There is a building, rotating, moving, and sizing system you can do with objects in Mashables to make robots. I am trying to replicate this in my game. I have decided to start with the sizing system, and it is acting odd.

Here is the problem: It seems like the block is scaling from both sides, and when I scale it to the edge of the screen, it scales very largely. I want to implement an increment.


f4cb17ff895dac03d6ae3488ad8e17fd01f44546

local scaleHandle = script.Parent
local block = workspace[script.Parent.Adornee.Name]
scaleHandle.MouseDrag:Connect(function(face, distance)
	if face == Enum.NormalId.Left or face == Enum.NormalId.Right then
		block.Size += Vector3.new(distance, 0, 0)
	end
	if face == Enum.NormalId.Top or face == Enum.NormalId.Bottom then
		block.Size += Vector3.new(0, distance, 0)
	end
	if face == Enum.NormalId.Front or Enum.NormalId.Back then
		block.Size += Vector3.new(0, 0, distance)
	end
end)

Screen Shot 2023-01-08 at 7.19.21 PM

Hello? This is a very urgent matter.

You need to also move the position by half the change in size, in the same direction.

Okay, so I’m using this script:

local scaleHandle = script.Parent
local block = workspace[script.Parent.Adornee.Name]
scaleHandle.MouseDrag:Connect(function(face, distance)
	if face == Enum.NormalId.Left or face == Enum.NormalId.Right then
		block.Size += Vector3.new(distance, 0, 0)
		block.Position += Vector3.new(distance / 2, 0, 0)
	end
	if face == Enum.NormalId.Top or face == Enum.NormalId.Bottom then
		block.Size += Vector3.new(0, distance, 0)
		block.Position += Vector3.new(0, distance / 2, 0)
	end
	if face == Enum.NormalId.Front or Enum.NormalId.Back then
		block.Size += Vector3.new(0, 0, distance)
		block.Position += Vector3.new(0, 0, distance / 2)
	end
end)

and it is super buggy.

How could I put an increment into this system?

What type of Instance is scaleHandle?

Its an adornment but that shouldn’t matter to the item it helps to detect if has been clicked on and dragged upon.

I have a question is this being done through the player side, and if so this could be solved quiet easily using the cameras position.

I provided an image:
image

I can’t find the documentation for the MouseDrag event you’re using anywhere. I need to know if distance is always positive or negative relative to the face, or relative to the part’s local space.

I am using the Handles instance.

Your code seems to assume that the distance will be relative to the part’s CFrame, so pulling out the front face would be a negative distance, and pulling the back face would be a positive. It doesn’t look like that’s correct though.

Also this script can be altered to make a cleaner script and smaller one as well:

local scaleHandle = script.Parent
local block = workspace[script.Parent.Adornee.Name]
local ToAxis = { [Enum.NormalId.Left] = 'X' ; [Enum.NormalId.Right] = 'X';
	[Enum.NormalId.Top] = 'Y';  [Enum.NormalId.Bottom] = 'Y';
	[Enum.NormalId.Front] = 'Z'; [Enum.NormalId.Back] = 'Z' }


scaleHandle.MouseDrag:Connect(function(face, distance)
local Axis = Enum.Axis[ToAxis[face] ]
	block.Size += Vector3.FromAxis(Axis) * distance
	block.Position += Vector3.FromAxis(Axis) * (distance/2)
end)


Okay, so, what am I supposed to do?

You can do this but you need Back to be +z and Front to be -z, which this doesn’t do, same as the original code.

Screen Shot 2023-01-08 at 8.55.24 PM
The code looks like this in the script.

Oh I believe you have to put them in brackets or they have to be in the same line which I didn’t do because I wasn’t able to see everything. Also there isn’t any negatives in my script the back on yours has a negative remove that as well.

It is still blue and red. There are still some errors it seems, and I have done everything you suggested.

You don’t need the back and front to be alter they want it to go on both sides they have to be the same on each side but I believe you mean from the position.