While true loop doesn't stop

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    The code works, but the while loop doesn’t stop

  2. What is the issue? Include screenshots / videos if possible!
    robloxapp-20230519-1959344.wmv (2.5 MB)

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried returning function tried repeat until still didn’t work

wait(0.0)
CarpetRolledOut.Size += Vector3.new(0,0,0.5)
CarpetRolledOut.Position += Vector3.new(0,0,-0.5)
end
-- 

To stop a while loop either use:

while CarpetRolledOut.Size.Z < 10 do
   ...
end

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

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