belalg1
(belol)
December 9, 2021, 10:02pm
#1
I am trying to stop or cancel the tween but I can’t run functions like :Cancel() or :Pause() on TweenPosition, how can I stop the tween ?
tw = image:TweenPosition(UDim2.fromOffset(3,0),Enum.EasingDirection.Out,Enum.EasingStyle.Sine,3, true)
wait(1)
tw = false --not working, I tried tw:Cancel() got error
1 Like
You forgot the play the tween in the first place.
You need to do tw:Play() and then tw:Cancel()
Sarchyx
(Sarchyx)
December 9, 2021, 10:05pm
#3
https://devforum.roblox.com/t/pause-localscript-execution-until-tweenposition-completes/238833/11
It has been considered an option to deprecate UI tween elements, because they have limitations and TweenService can do exact same things, just use it.
local Tween = TweenService:Create(Gui, TweenInfo.new(), {Position = UDim2.new()})
Tween:Play()
task.wait(1)
Tween:Cancel()
2 Likes
belalg1
(belol)
December 9, 2021, 10:07pm
#4
I tried got an error (the tween working without :Play())
Check out this article. It should have everything you need
Unfortunately, to have the tween “pause” with TweenPosition
(and TweenSize
respectively), you have to override it with another TweenPosition
call.
gui:TweenPosition(UDim2.new(1, 0, 1, 0), "Out", "Quad", 10, true)
wait(3)
gui:TweenPosition(UDim2.new(gui.Position.X.Scale, 0, gui.Position.Y.Scale, 0), "Out", "Quad", 0, true)
There’s also no option to “cancel” the tween either, you’d have to do similar to the above.
Forummer
(Forummer)
December 10, 2021, 8:32am
#7
local image = script.Parent
local ts = game:GetService("TweenService")
local tween = ts:Create(image, TweenInfo.new(3, "Sine", "Out"), {Position = UDim2.fromOffset(3, 0)})
tween:Play()
task.wait(1)
tween:Cancel()
The solution applied to your example, don’t forget to declare variables locally to integrate them into the local environment (local variables are quicker to reference and access).