• 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.
    • 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.

Gravity Cycling Question

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

simong1993

Active Coder
Staff Team
Guardian
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

The_Techist

New Coder
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.
 

Top