generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Is there a way to have a loop

Previous Thread :: Next Thread 
Korniak is not online. Korniak
Joined: 09 Aug 2013
Total Posts: 3538
13 Apr 2016 03:07 PM
but not wait for it to finish?
Report Abuse
ghostleader is not online. ghostleader
Joined: 16 Feb 2008
Total Posts: 1131
13 Apr 2016 03:08 PM
of course.


while true do
wait()
-- repeat something forever.
end
Report Abuse
ghostleader is not online. ghostleader
Joined: 16 Feb 2008
Total Posts: 1131
13 Apr 2016 03:09 PM
Oh wait, I see what you mean.

What would be a use case for this?

You could do this:

while wait() do
spawn(function()
do something here
end)
end
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
13 Apr 2016 03:09 PM
spawn(function()
for i = 1,5,1 do
print(i)
end
end)


Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
13 Apr 2016 03:15 PM
Just throw the loop in a coroutine:

coroutine.wrap(function()
while wait() do
-- do stuff
end
end)()
print("After the coroutine yields (calls wait() or any function classified as YieldFunction in the docs), it will continue running the code from the script that created the coroutine.")

Alternatively, you can throw the loop into Spawn, but be aware that the loop won't start running until the next frame.

More information:
http://wiki.roblox.com/index.php?title=Function_dump/Coroutine_manipulation
http://wiki.roblox.com/index.php?title=Beginners_Guide_to_Coroutines
http://wiki.roblox.com/index.php?title=Threading
http://wiki.roblox.com/index.php?title=Thread_scheduler
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image