Help with while

Why when me need make the very fast system, im using the
repeat
// my code
until 1 ~= 1
and me need write the:
repeat
wait(sec)
// my code
until 1 ~= 1
to fix the:
Script timeout the exists.
How im can fix?

2 Likes

So what are you trying to achieve here?

2 Likes

Of what I gathered from what you posted, you could use

while true do

wait()

-- code here
end
1 Like

If your loop runs forever without any yields it will lag out your game. You have to either put a yield like wait() or game:GetService("RunService") or make sure it finishes, so your game doesn’t crash.

2 Likes

Indeed, one of the two is needed.

2 Likes

Im tried to use the all whiles, but all whiles givs me the error with script timeout.
My script with changing position doesn’t have time to normal changing and part is falling down.
Im think that this problem with wait(), welp…

2 Likes

If wait() isnt fast enough try using RunService

1 Like

Wut

That loop you’re implementing would just result back as it being infinite & would result in a script exhaustion error (OR FIRING OVER 500,000 LINES OF CODE AT ONCE)

If you’re wanting to only implement a couple of certain loops, you can use the for loop which will run a number of times depending on how much you want:

for Loop = 1, 10 do --1 is the starting position, 10 is the end position
    --Do code here
end

This will not break the script since you’re only looping that line of code 10 times

2 Likes

Do you mean a for loop like this?

for i = 1, 10 do
    -- code
end
1 Like

My brain just died to the point where I forgot that toasters needed to be plugged in for it to work

YES I MEANT THAT KIND OF LOOP

1 Like

bruh, part is falling with it…

What are you trying to do with the part?

BRUUUHHH… me need just use the Radius to make it…

This can be a useful alternative, as it only runs after every frame is rendered:

while 1 == 1 do
    game:GetService(“RunService”).Heartbeat:Wait()
    -- code here!
end

Im think that the problem is solved, because im forgot about Region3, he creates the region, and im can check who in this region. I make the script with changing position from: Part.CanCollide = false. Me need was make the region…