Well we all know that too much while wait() do
or while true do
can cause crashes, which we don't want those.
Now I learned that if I want to change a text to a certain value then a better way then using loops is doing the .Changed
event. But what if I'm trying to continuously Tween a frame? Is there a better way than looping?
This is my script;
local NB = script.Parent while true do wait(0.00000000000000000000000000000000001) NB:TweenPosition(UDim2.new(0, 840,0, 220),'In','Sine',0.5) wait(0.00000000000000000000000000000000001) NB:TweenPosition(UDim2.new(0, 840,0, 240),'Out','Sine',0.5) end
If there is a better way then looping for forever tweens then please help. I need to learn a better way then just looping. It causes crashes and it's annoying.
You can:
1) add a call to wait() either in the code of the loop, or as the condition for the loop.
Example:
local NB = script.Parent while wait() do wait(0.00000000000000000000000000000000001) NB:TweenPosition(UDim2.new(0, 840,0, 220),'In','Sine',0.5) wait(0.00000000000000000000000000000000001) NB:TweenPosition(UDim2.new(0, 840,0, 240),'Out','Sine',0.5) end
2) In addition to 1, you can also create an entirely separate thread (script) to handle the loop.
Example:
local NB = script.Parent spawn(function() while wait() do wait(0.00000000000000000000000000000000001) NB:TweenPosition(UDim2.new(0, 840,0, 220),'In','Sine',0.5) wait(0.00000000000000000000000000000000001) NB:TweenPosition(UDim2.new(0, 840,0, 240),'Out','Sine',0.5) end end)
Roblox's "spawn" function will run the function in an entirely new thread (a thread is basically another name for a ROBLOX script).