I want to tween the camera back to player, however it does not work with the script I’m trying. The camera goes to the player instantly then tweens back to my starting camera then instantly the camera goes to the player without tweening.
Current Script:
local camCFrame = camera.CFrame
local camDistance = camCFrame.p - Player.Character.Head.Position
local newPos = Player.Character.Head.Position + camDistance
local cameraCFrame = CFrame.new(newPos, newPos + camCFrame.LookVector)
--local newPos = Player.Character.Head.Position + camDistance
--local cameraCFrame = CFrame.new(newPos, newPos + camera.CFrame.LookVector)
local l = ts:Create(camera, ti, {CFrame = cameraCFrame}):Play()
--workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
l.Completed:Connect(function()
camera.CameraSubject = Player.Character.Humanoid
camera.CameraType = "Custom"
end)
l is actually nil because calling :Play() on a tween doesn’t return a value. Consequently, the Completed connection won’t work because it doesn’t refer to the tween.
Try assigning the tween to l, then call :Play() and create the Completed connection.
local l = ts:Create(camera, ti, {CFrame = cameraCFrame})
l:Play()
l.Completed:Connect(function() ... end)
I did this, but it didn’t solve the problem that I mentioned, the tweening doesnt go from starting point to Player, it just goes from player to starting point to player.
Is there code after this which also manipulates the camera? The only other thing I can think of is using l.Completed:Wait() to stop the code until the tween is complete, then reset the camera.
local l = ts:Create(...)
l:Play()
l.Completed:Wait() -- WAITS until the tween is finished, unlike the connection
-- code continues...
There is a code that manipulates the camera, which is just setting it to the starting point. The problem I think its CamDistance but I don’t really know. The tween finishing doesn’t affect the camera in a bad way such as the problem I’m currently dealing with.
So is tweening the camera back to its original CFrame (the CFrame it had before manipulating the camera) what isn’t working?
If so, you could store the initial camera CFrame before manipulating it, then tween the camera back to the original CFrame when you’ve finished manipulating it.