Or use the following if statement inside the while loop to break it.
if CarpetRolledOut.Size.Z >= 10 then break end
Finally instead of a while loop you can use a for loop like so:
local start, final = 1, 10 -- beginning and final Z state
local steps = 10
local stepSize = (start - final)/steps
for i, steps do
task.wait() -- waits one frame
CarpetRolledOut.Size += Vector3.new(0,0,0.5)
CarpetRolledOut.Position += Vector3.new(0,0,-0.5)
end
I would highly suggest you take a look at repeat. Here is an example:
repeat
CarpetRolledOut.Size += Vector3.new(0,0,0.5)
CarpetRolledOut.Position += Vector3.new(0,0,-0.5)
until CarpetRolledOut.Size.Z >= 10 -- Change the 10 to how much you want the carpet to extend
By the way, if we exclude your methods, I would highly suggest you use tweenservice as they are way more secure, easy and smooth to work with. Here is the API: TweenService | Roblox Creator Documentation