I wish to keep the same orientation when resizing a model. For some reason the Trunk changes orientation when I resize it.
local button = script.Parent
local buttonPrompt = button:WaitForChild("Buy")
local treeModel = workspace.Tree:GetChildren()
local function upgradeTree()
local originalPosition = workspace.Tree.PrimaryPart.Position
for _, parts in pairs(treeModel)do
if parts:IsA("Part") then
local newSize = parts.Size + Vector3.new(1,1,1)
-- get orientation of the part (since the parts orientation is changing)
parts.Size = newSize
parts.CFrame = CFrame.new(originalPosition + Vector3.new(0,newSize.Y / 2, 0))
-- set orientation of the part
end
end
end
I wasn’t having much luck with the code so I made them comments.
2 Likes
I don’t see why the models orientation would change if you give each part a new size? Have you tried removing the line:
parts.CFrame = CFrame.new(originalPosition + Vector3.new(0,newSize.Y / 2, 0))
I tried running the following script, located as seen in the picture:
script.Parent.Size = script.Parent.Size + Vector3.one
PS: I don’t know if you are aware or intentionally don’t want to use this function, but ScaleTo() can scale models. I can see that this way of scaling is different from scaling each part, but i just wanted to mention it in case.
No I have not, I made a button that increases the size of a tree when pressed. The tree then grows and extends through the baseplate. I decided to increase Y by half of the size to reposition the tree so the base starts at the baseplate instead of through it. In doing so the (basic model of the tree with the primary part set to the trunk “which is a basic cylinder”) decided to spin 90 degrees. Idk why that happened but in trying to correct the issue all manner of weird stuff was happening. One attempt saw the tree came further off the ground each time the size was changed, another attempt saw the tree head up and away from the original location and it didn’t make any sense.
Removing that line makes it size properly but it ends up increasing in size from the original position causing each part to overlap each other and resizing through the floor.
Isn’t ScaleTo() used for humanoids?
You are changing cframe which contains orientation in it i would suggest using position