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

TweenPosition callback being called at start of Tween instead of when Tween completes?

Asked by 5 years ago
--A local script inside a frame
function Done()
    print(script.Parent.AbsolutePosition)
end
local Direction = Enum.EasingDirection.InOut
local Style = Enum.EasingStyle.Quad
local Time = 1
script.Parent:TweenPosition( UDim2.new(0,50,0,50),Direction ,Style,Time,true,Done())

I expected Done() to print 50,50 but its being called when the tween starts instead of when it ends, what am I doing wrong?

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

You are calling Done() instead of passing it in as an argument, that's why it ran on the same line as you used TweenPosition. Calling a function would return a value which in this case is nil. What you have to do is remove the parentheses ().

--A local script inside a frame
function Done()
    print(script.Parent.AbsolutePosition)
end
local Direction = Enum.EasingDirection.InOut
local Style = Enum.EasingStyle.Quad
local Time = 1
script.Parent:TweenPosition( UDim2.new(0,50,0,50),Direction ,Style,Time,true,Done) -- removed parentheses
0
Is there anyway to pass a variable to Done? isitfun4 14 — 5y
0
instead of passing Done use an anonymous function to call it: function() Done(args) end GoldAngelInDisguise 297 — 5y
0
Done is an anonymous function as well. User#24403 69 — 5y
Ad

Answer this question