Tween.Completed never fires even after the tween is finished

I’m making a tycoon game for the heck of it and am trying to add some visual flair to when you purchase something. Below is the code for tweening in all the parts that have been displaced earlier in the code. However, Tween.Complete never actually activates to re-enable the collisions.

-- parts are the parts being tweened, and positions and orientations are their target position and orientation respectively
for _, part in parts do
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
	local tween = tweenService:Create(part, tweenInfo, {Position = positions[_], Orientation = orientations[_], Transparency = 0})
	tween.Completed:Connect(function()
		part.CanCollide = true
		part.Velocity = part.CFrame:VectorToWorldSpace(Vector3.new(0,0,12)) -- cuz it breaks the conveyors
		print('dunzo bunzo')
	end)
	print('started tween...')
	tween:Play()
end

Is there anything that stands out as being the culprit?

1 Like

You’re saying that “started tween…” prints but “dunzo bunzo” doesn’t? I don’t see anything wrong with the code.

positions[_]

orientations[_]

on the tweenService tween goal which will error out and before the tween even starts

here would be your corrected code:

-- parts are the parts being tweened, and positions and orientations are their target position and orientation respectively
for index, part in parts do
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
	local tween = tweenService:Create(part, tweenInfo, {Position = positions[index], Orientation = orientations[index], Transparency = 0})
	tween.Completed:Connect(function()
		part.CanCollide = true
		part.Velocity = part.CFrame:VectorToWorldSpace(Vector3.new(0,0,12)) -- cuz it breaks the conveyors
		print('dunzo bunzo')
	end)
	print('started tween...')
	tween:Play()
end

this isn’t really the problem, the tween itself works fine, it tweens completely right, it just never “completes” (according to the event)

it prints “started tween” but never the “dunzo bunzo”, and no errors appear

yes, i also don’t see anything wrong with the code but apparently something’s not working (see video above)

false


Try connecting the tween after you start playing it, could be you can only making Completed connections when the tween is playing.

This is a single thread so in theory it should go by order, first the tweeninfo is declared then tween is declared then the tween.Completed signal is connected, then a print is outputted, and finally the tween is played. Maybe assign the connection to a variable and check the .Connected variable. (SIDE NOTE: if you only running the completed part once, use Once() instead of Connect())

i did everything you said, it says that it IS connected, but it still never fires
image

do you perchance have a another variable also named tween?

nope, only the one (unless you count the iteration but i don’t think that matters)

sounds dumb, but does your code atleast run, like the can collide is set to true and veolicty as well?

nope, the entire connected function doesn’t execute

print its playback state, tween.PlaybackState, and also try like adding before all that code a print inside the completed block.

I think you need to put tween.Completed after you play the tween. Since it won’t return true until tween is played.

Passes the Enum.PlaybackState of the tween to any connected functions to give an indication of why the tween ended. Note that calling TweenBase:Pause() does not fire the Completed event.

Not really.

the playback state is printed as Enum.PlaybackState.Begin right after starting (which i assume is normal)

curiously, i put a wait(1) after the start to print its later value and it started working, but when i changed it to be 0.01 this behavior stopped. i assume there’s some issue with rapidly creating tweens?? i don’t know how i would get around this

I never encountered such issue also

Name Value Summary
Begin 0 The tween has been created, but has yet to be played. After exiting this state, the tween never enters it again.

lets instead of using tween.completed
use task.delay(time, function) or

use the code sample here to detect the changed playbackstate

i tried replicating the same thing and it did work

for index, part in Parts do
	print(index, part)
	part.Parent = workspace
	part.Anchored = true
	part.Transparency = 1
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quint, Enum.EasingDirection.Out)
	local tween = game.TweenService:Create(part, tweenInfo, {Position = Position.Position, Size = Size, Transparency = 0})
	tween.Completed:Connect(function()
		print("Completed")
		part.CanCollide = true
	end)
	tween:Play()
end

i tried everything, it only works when i do wait(), i’m actually stumped