Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is there a better way to Continuously Tween a Frame without using a loop?

Asked by 7 years ago

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.

0
While wait() do shouldn't be causing you crashes. While true do should cause crashes if you don't have a yield inside your looped code. Personally I would use a repeat (code here) until loop instead though as you can stop it with a certain condition. Be sure to add a yield though. LordProxius 17 — 7y
0
not necessary to do wait(0.00000...ect1) just use wait() abnotaddable 920 — 7y
0
I feel like wait() takes longer BlackOrange3343 2676 — 7y

1 answer

Log in to vote
-2
Answered by
movsb 242 Moderation Voter
7 years ago

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

Ad

Answer this question