The problem here is that when you change the .Size of a part, if it overlaps with anything, it will move on top to make room.
You can set .CFrame to combat this behavior -- but you have to know where it was before the problematic shifting around from changing the Size.
Depending on the context, it can be better to make changes relative to where you are now (like you do in line 4), but it is often cleaner to be relative to where you started:
local home = script.Parent.CFrame
local size = script.Parent.Size
for i = 1, 300 do
script.Parent.CFrame = home * CFrame.new(0, 0, 0.1 * i)
script.Parent.Size = size + Vector3.new(0.2 * i, 0, 0)
wait()
end
script.Parent:Destroy()
Also keep in mind that the amount of time wait will pause for is variable, and it can be good practice to actually use the time that has elapsed.
A loop written like this (not relative to where it was in the previous step) is a lot easier to transform into that, since you can just replace i with the time elapsed times some factor:
local started = tick()
repeat
local elapsed = tick() - started
local i = elapsed * 30
script.Parent.CFrame = home * CFrame.new(0, 0, 0.1 * i)
script.Parent.Size = size + Vector3.new(0.2 * i, 0, 0)
wait()
until elapsed > 10
script.Parent:Destroy()
2 comments
Anchor the parts?
that doesnt work.. :(