My tween plays, but when I wait for it to finish, it never fires. The tween happens and the tween finishes, but when it does I never get the DONE printed
function Camera.Tween(tweenProperties, tweenInfo)
CurrentCamera.CameraType = Enum.CameraType.Scriptable
print("DOING TWEEN")
local Info = tweenInfo or DefaultTweenInfo
local TweenObject = TweenService:Create(
CurrentCamera,
Info,
tweenProperties
)
TweenObject:Play()
print("TWEENING", Info)
return TweenObject
end
--// called from a function
local Tween = Camera.Tween({
CFrame = Character.PrimaryPart.CFrame * CFrame.new(0, 2, 10),
FieldOfView = 70
})
print("PLAYING")
coroutine.wrap(function()
Tween.Completed:Wait()
print("DONE") -- NEVER PRINTS
CurrentCamera.CameraType = Enum.CameraType.Custom
end)()
I have also tried
if Tween.PlaybackState == Enum.PlaybackState.Playing then
Tween.Completed:Wait()
end
Calling coroutine.wrap() by itself will not run. You need to do this:
local f = coroutine.wrap(function()
Tween.Completed:Wait()
print("DONE") -- NEVER PRINTS
CurrentCamera.CameraType = Enum.CameraType.Custom
end)
f()--call the coroutine
Are you sure there’s not some external issue causing this? I tested it with a part in workspace named Bob and this code and it worked fine for me (printed “Done”):
local TweenService = game:GetService("TweenService")
local function customTween(tweenProperties: {}, tweenInfo: TweenInfo): TweenObject
local info = tweenInfo or TweenInfo.new(1)
local tweenObject = TweenService:Create(
workspace.Bob,
info,
tweenProperties
)
tweenObject:Play()
return tweenObject
end
local tween = customTween({Position = workspace.Bob.Position + Vector3.new(0, 4, 0)})
tween.Completed:Wait()
print("Done")
Yes, the tween is playing and it does finish, but when it finishes it stays locked in position and not following the character (cause its not on custom)
coroutine.wrap(function()
Tween.Completed:Wait()
print("DONE") -- NEVER PRINTS
CurrentCamera.CameraType = Enum.CameraType.Custom
end)()
Since coroutine.wrap() just returns a function value which can be called to execute the created coroutine you need only append a pair of enclosing parentheses in order to call this returned function value.
function Camera.Tween(tweenProperties, tweenInfo)
CurrentCamera.CameraType = Enum.CameraType.Scriptable
print("DOING TWEEN")
local Info = tweenInfo or DefaultTweenInfo
local TweenObject = TweenService:Create(
CurrentCamera,
Info,
tweenProperties
)
print("TWEENING", Info)
return TweenObject
end
--// called from a function
local Tween = Camera.Tween({
[CFrame] = Character.PrimaryPart.CFrame * CFrame.new(0, 2, 10),
FieldOfView = 70
})
Tween:Play()
print("PLAYING")
coroutine.wrap(function()
Tween.Completed:Wait()
print("DONE") -- NEVER PRINTS
CurrentCamera.CameraType = Enum.CameraType.Custom
end)()