Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

The_Techist

New Coder
Hello all, I have a fairly simple question. I am new to LUA and don't yet understand exactly how for loops work in this language yet. I have a code that I have integrated into my workspace that changes the gravity after 10 seconds as seen here:

Code:
script.Parent.Gravity = 500
wait (10)
script.Parent.Gravity = 1

This works, but I need to turn it into an infinite loop if possible where every ten seconds it will cycle between 500 gravity and 1 gravity. Can someone tell me how I would edit this code to become an infinitely looping code?
 
Solution
Hey now i am not a massive LUA fan, BUT you could do a While true loop like this:-

Code:
while true do
          script.Parent.Gravity = 500
          wait (10)
          script.Parent.Gravity = 1
end

This should loop the code every 10 seconds as it will always be true
Hey now i am not a massive LUA fan, BUT you could do a While true loop like this:-

Code:
while true do
          script.Parent.Gravity = 500
          wait (10)
          script.Parent.Gravity = 1
end

This should loop the code every 10 seconds as it will always be true
 
Solution
Hey now i am not a massive LUA fan, BUT you could do a While true loop like this:-

Code:
while true do
          script.Parent.Gravity = 500
          wait (10)
          script.Parent.Gravity = 1
end

This should loop the code every 10 seconds as it will always be true
This worked perfectly thank you! I couldn't figure out where to position the "While true do" line, but that is very self explanatory thank you.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom