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?
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 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())
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.
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