If you want the Script to repeat forever, then use while
or repeat until
, the first method can run however many times you like, can also have a circumstance required for the loop to run, repeat
can also do this, yet both will immediately break whenever the given circumstance is no longer true. This would look like so
1 | while true wait(BeforeNextRun) do |
2 | local Part = Instance.new(“Part”); Part.Parent = workspace |
4 | local CurrentCFrame = Part.CFrame |
5 | Part.CFrame = Part.CFrame * Part.CFrame() + Vector 3. new(CurrentCFrame.p) |
This will run forever, every time[BeforeNextRun]. If it’s a conditional statement, it would look like this
03 | while Boolean wait(BeforeNextRun) do |
04 | local Part = Instance.new(“Part”); Part.Parent = workspace |
06 | local CurrentCFrame = Part.CFrame |
07 | Part.CFrame = Part.CFrame * Part.CFrame() + Vector 3. new(CurrentCFrame.p) |
14 | wait(SameTimeAsBeforeNextRun * 3 ) |
You can also use break
, this works for both methods. It can be called wherever inside the loop, yet be careful as break
immediately breaks whichever loop it is called in. Sometimes if you have more than one and you call this method, whichever loop it was inside it will break the corresponding one, it will not break the first one.
Then you have repeat
, it would look like this
04 | repeat wait(BeforeNextRun) |
06 | local Part = Instance.new(“Part”); Part.Parent = workspace |
08 | local CurrentCFrame = Part.CFrame |
09 | Part.CFrame = Part.CFrame * Part.CFrame() + Vector 3. new(CurrentCFrame.p) |
15 | wait(SameTimeBeforeNextRun * 3 ) |
Unlike while
, return
always requires a conditional statement. Yet you can use return
as a Yield, this would usually be seen at the top of a Script yet can be applied anywhere, this method is used to yield the Script until curtain requirements are met, would look like so
Hope this helps, spent a while putting this together, if so, don’t forget to Upvote and Accept this Answer! Good luck!
Closed as Not Constructive by TheeDeathCaster
This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.
Why was this question closed?