How to Effectively use While loops

Hello there, recently I learnt about while loops and I made the most simple while loop I could think of.


while john < 5  do 
	game.Workspace.johnspart.Transparency = 0.6
end

In the output this appeared and my studio almost crashed  13:59:08.012  Script timeout: exhausted allowed execution time  -  Server - Script:3. How can I use while loops then if it will crash?
1 Like

put wait() or ur studio will crash

everytime u use loop dont forget to put wait()

where should I put it? please tell me where

u can put inside on the loop thats it

like this
while john < 5 do
wait()
game.Workspace.johnspart.Transparency = 0.6
end

local john = 1

while john < 5  do 
	wait(5)
	game.Workspace.johnspart.Transparency = 0.6
end

Blockquote this good?

Yes, that’s good. Or you could just make the wait(5) to wait()

1 Like

Works, thank you for the help! I am still new to scripting so it really helps.

what happens if you put wait() instead of wait (5)

No problem, we were all beginners at some point.

nope just keep scripting and just post here if u have more problem

The number inside a wait is how many seconds itll wait before continuing.

the studio will not crash and u can just put wait() cuz u dont have to want until 5 second

I know but he said to put wait() instead of wait (5)

what happened if you used wait() in other things, for example

game.StarterGui.ScreenGUI.Frame.Visible = true
wait()
game.StarterGui.ScreenGUI.Frame.Visible = true

when u put wait() the value of waiting is 0.3 if u put wait(5) the value of waiting is 5

Okay thank you, I didn’t realise just putting wait() still waits for 0.3 seconds

1 Like

Just putting wait() doesn’t mean to wait for 0.3. That information is wrong. Just putting wait means the loop will wait for 0.001 seconds and so fourth.

1 Like

wait() yields for about 0.03 seconds, not 0.001

3 Likes