local elevator = script.Parent if elevator.Glass.Size < Vector3(28, 12, 2) then elevator.Glass.Size = elevator.Glass.Size + Vector3.new(0,0.5,0) elevator.Glass.Position = elevator.Glass.Position + Vector3.new(0,0.2,0) wait() end for i= 1,100 do wait() elevator:SetPrimaryPartCFrame(CFrame.new(elevator.PrimaryPart.Position - Vector3.new(0,1,0))) end
Whenever you change the Size
property of a part directly, it resizes equally in both directions on each axis you change.
So if you did something like:
part.Size = part.Size + Vector3.new(0, 1, 0)
It would add .5 studs to the top of the part, and .5 studs to the bottom of the part, so as to maintain it's position.
In order to give the illusion of it growing in only one direction, we need to offset it in the direction we want it to grow in, by half the amount we add to it's size.
So if we wanted the part to grow upwards, our script might look like this:
local part = script.Parent part.Size = part.Size + Vector3.new(0, 1, 0) part.Position = part.Position + Vector3.new(0, .5, 0)
There are 2 issues with this approach:
Size
is subject to collisions, so if changing the size causes the part to intercept with another, it will change the position and mess up our math.Position
is subject to collisions, so the same thing.To solve this, before changing the Size
we should record the current CFrame
of the part, and then after we change it's Size
, we should offset the part's CFrame
from the one we recorded.
local part = script.Parent local cf = part.CFrame --record current CFrame part.Size = part.Size + Vector3.new(0, 1, 0) part.CFrame = cf + Vector3.new(0, .5, 0)
In order to make this easier to edit, we might create a variable called size_step
which records the increment in which we want to resize this
local part = script.Parent local size_step = Vector3.new(0, 1, 0) -- step is +1 stud(s) vertically local cf = part.CFrame --record current CFrame part.Size = part.Size + size_step part.CFrame = cf + size_step / 2
Now to make the part move up at the same time:
This is the easiest, just add the extra vector onto the end of the line changing the CFrame
.
local part = script.Parent local cf = part.CFrame --record current CFrame local size_step = Vector3.new(0, 1, 0) -- step is +1 stud(s) vertically local move_step = Vector3.new(0, .2, 0) --step is +.2 studs(s) vertically part.Size = part.Size + size_step part.CFrame = cf + size_step / 2 + move_step
That's it! Now all we have to do, is put it in a loop, and change the steps to what we want!
local part = script.Parent local size_step = Vector3.new(0, .05, 0) -- step is +.05 stud(s) vertically local move_step = Vector3.new(0, .08, 0) --step is +.08 stud(s) vertically for i = 1, 500 do wait() local cf = part.CFrame --record current CFrame part.Size = part.Size + size_step part.CFrame = cf + size_step / 2 + move_step end