.Completed not working properly for tweens?

I’m having a problem (only on mobile for some reason) where this script stops

local Out = TweenService:Create(Frame, TweenInfo.new(1), {Position = UDim2.new(0.5, 0, 0, 0)})
Out:Play()

Out.Completed:Wait()

And I assume that’s because the tween might have finished before the script got to the :Wait(), and thus causing an infinite yield. So I tried

local Out = TweenService:Create(Frame, TweenInfo.new(1), {Position = UDim2.new(0.5, 0, 0, 0)})
Out:Play()

if not Out.Completed then
	Out.Completed:Wait()
end

But that doesn’t wait at all (the scripts continues before the tween has finished)

Like

if Out.PlaybackState ~= Enum.PlaybackState.Playing then
		Out.Completed:Wait()
	end

??

Depends on how you are using it but i do like this

local Out = TweenService:Create(Frame, TweenInfo.new(1), {Position = UDim2.new(0.5, 0, 0, 0)})
Out:Play()

Out.Completed:Connect(function())
and i put here the next tween
end

if Out.PlaybackState ~= Enum.PlaybackState.Playing then
	-- What you want to happen when out finished playing
end

I think he meant like that

That would be if it’s not currently playing, wait for it to finish. That doesn’t make much sense. Try changing the ~= to an ==.

Also, the reason your first code sample didn’t work is because if Out.Completed would just check if the Completed event exists, which it does.

2 Likes