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

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

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

✓ Accepted answer

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

3 comments

0

Is there anyway to pass a variable to Done?

0

instead of passing Done use an anonymous function to call it: function() Done(args) end

0

Done is an anonymous function as well.

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