Need a little help to understand model scaling

I press a button and the tree scales up but it scales through the floor. I assume the models position is the same before and after so I’m attempting to alter the position. I figured since the scale is Y and -Y I should adjust the Position.Y to half the scale increase. It’s not correct. any help would be much appreciated.


local function upgradeTree()
	local originalScale = treeModel:GetScale()
	local originalPosition = treeModel:GetPivot()
	local change = 1.1
	treeModel:ScaleTo(originalScale * change)
--trying to keep the model's base firmly on the ground with the new model scale. The scaling above works fine.
	treeModel:PivotTo(originalPosition + Vector3.new(0,originalPosition.Y * change/2,0))
end

Furthermore, if I don’t try and set the position of the model I end up with the model scaling through the baseplate.

Try moving the pivot point to the bottom of the model, then only scale the model to the desired size.

Seems I fixed it.


local button = script.Parent
local buttonPrompt = button:WaitForChild("Buy")
local treeModel = workspace:WaitForChild("ChristmasTree")
local scaleMulti = 0.05

local function upgradeTree()
	local originalScale = treeModel:GetScale()
	print(originalScale)
	local treePositionX = treeModel.PrimaryPart.Position.X
	local treePositionY = treeModel.PrimaryPart.Position.Y
	local treePositionZ = treeModel.PrimaryPart.Position.Z
	
	treeModel:ScaleTo(originalScale + scaleMulti)
	
	local newScale = treeModel:GetScale()
	local difference = (newScale - originalScale) / 2
	
	treeModel:MoveTo(Vector3.new(treePositionX, treePositionY + difference, treePositionZ))
end

buttonPrompt.Triggered:Connect(function(plr)
--code
  upgradeTree()
--more code
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.