Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

GUI Tween stops moving occasionally?

So, I have a local script in a gui image label that looks like this:


local fight = script.Parent

while true do 
	fight:TweenPosition(UDim2.new(0.5, -200,0.5, -80), "InOut")
	wait(1)
	fight:TweenPosition(UDim2.new(0.5, -200,0.5, -60), "InOut") 
	wait(1)
end

What it's supposed to do is to make the image bob up and down. It works fine, but occasionally, the image stops moving for a few seconds and starts to move again. Am I missing something in the script?

2 comments

0

You don't have the argument "override" set, which is set to 'false' by default. This means that if, while it's moving, it is asked to tween to somewhere else, it will change its current task and move to the new place, if its set to true.

1 answer

✓ Accepted answer

The missing element which is causing the delay is that the tweening waits until it reaches the exact position, to be able to tween again.

TweenPosition() takes six parameters:

Parameter 1: End position as UDim2 2: Easing direction (which you have indicated as "InOut") 3: Easing style ("Quad", "Sine", "Elastic" etc.) 4: Time (The amount of time it takes to do the transition) 5: Override (Boolean value, if set to true = it has to reach its End position before it's able to start another transition) 6: Callback function (Will return whether the tween will be able to start a transition)

To be able to fix this problem, you would want to set the Override value to true when you call TweenPosition() to true since you do not want the program to wait until the End Position is reached to execute another transition.

So the code will look something like this:

local fight = script.Parent

while true do 
    fight:TweenPosition(UDim2.new(0.5, -200,0.5, -80), "InOut", "Quad", 1.5, true)
    wait(1)
    fight:TweenPosition(UDim2.new(0.5, -200,0.5, -60), "InOut", "Quad", 1.5, true) 
    wait(1)
end

Hope this helped!

2 comments

0

I must thank you for fixing my problem. I'll remember this for future uses.

0

Happy to help :)

This discussion is preserved as it was. New answers, comments, and votes are closed.