Mouse 3d positioning bug with roblox studio like editor ‏‏‎ ‎

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

I’m suffering from a bug while developing my obby creator-like game, I would like a way to fix it and scripting examples would be helpful!

  1. What is the issue? Include screenshots / videos if possible!

Whenever i move my mouse to position far away from the part, it sizes up.

As you can see that is not want I want as I am trying to creating a sizing system similar to that of roblox studio. The red orb thingy should be aligned with the mouse instead of going somewhere else

  1. What solutions have you tried so far?

This type of thing is not popular enough for solutions on devhub, i have spent hours looking.

Ill give 1 robuck to whoever figures out the issue! This should not be a difficult fix!

  1. Extra Details

Here are 2 parts of my code that are related to the issue.

Functions

function roundToStep(initialValue:number,step:number)
	if typeof(initialValue) == "Vector3" then
		local dividedvalue = initialValue/step
		local roundedvalue = dividedvalue:Floor()*step
		return roundedvalue
	else
		local roundedValue = math.floor(initialValue/step)*step
		return roundedValue
	end
end

function findaxis(l,s, f) -- oh this looks confusing, this just turns all values in the vector3/cframe not on the target axis (l) to f, and the value on the target axis to s.
	local function fi(f,strin)
		if typeof(f) == "CFrame" or typeof(f) == "Vector3" then
			return f[strin]
		else
			return f
		end
	end
	local thing = Vector3.new((l == "X" and s) or fi(f,"X"), (l == "Y" and s) or fi(f,"Y"), (l == "Z" and s) or fi(f,"Z"))
	return thing
end

local function find3dmousepos(Part, MaxRange) -- "Part" is what you filter
	
	local Origin = workspace.CurrentCamera:ScreenPointToRay(Mouse.X, Mouse.Y).Origin
	local Direction = (Origin - workspace.CurrentCamera.CFrame.Position).Unit
	
	local IgnoreParams = RaycastParams.new()
	IgnoreParams.FilterDescendantsInstances = {Part}
	IgnoreParams.FilterType = Enum.RaycastFilterType.Exclude
	
	local Result = workspace:Raycast(Origin, Direction * MaxRange, IgnoreParams)
	
	return Result and CFrame.new(Result.Position) or CFrame.new(Origin + Direction)
end

Mini Function in Main Function

v.MouseButton1Down:Connect(function()
	if CurrentlySizingPart == false then
		CurrentlySizingPart = true
		local startMousePos = v.CFrame.Position
		local startPos = Part.Position
		local startSize = Part.Size
		MouseMovingConnection = Mouse.Move:Connect(function()
			local delta = roundToStep((find3dmousepos(Part,1000).Position - startMousePos)[Letter],1)
			local axisVector = findaxis(Letter, 1, 0)
			local sign = math.sign(delta)
			local magnitude = roundToStep(delta,1)
			local offset = axisVector * magnitude
			local newSize = oldSize + offset
			local newPosition = originalPosition + (axisVector * (magnitude*-Number / 2))
			Part.Size = newSize
			Part.Position = newPosition
		end)
	end
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category. Ok i get it you bot