I’m going to have to restart studio, give me a second.
Would I need the line
tween.Completed:Wait()
I don’t really understand its purpose.
It waits until the tween is completed.
Also, try out this code i may have fixed the problems:
local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false
local camera = game.Workspace.Camera
local sceneTime = 20
local tween = nil
local forcestop = false
local tweeninfo = TweenInfo.new(
sceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
local player = game.Players.LocalPlayer
function TweenFunction(camera1, camera2, ending)
if forcestop == false then
camera.CFrame = camera1.CFrame
tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
tween:Play()
tween.Completed:Wait()
end
end
script.Parent.MouseButton1Click:Connect(function()
forcestop = true
if tween then
tween:Cancel()
tween:Cancel()
tween:Cancel()
tween:Cancel()
tween:Cancel()
end
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
script.Parent.Parent.Parent.Enabled = false
end)
repeat
camera.CameraType = Enum.CameraType.Scriptable
if not forcestop then
TweenFunction(cams.Camera1, cams.Camera2, false)
end
if not forcestop then
TweenFunction(cams.Camera3, cams.Camera4, false)
end
if not forcestop then
TweenFunction(cams.Camera5, cams.Camera6, false)
end
if not forcestop then
TweenFunction(cams.Camera7, cams.Camera8, false)
end
if not forcestop then
TweenFunction(cams.Camera9, cams.Camera10, true)
end
camera.CameraType = Enum.CameraType.Custom
local character = player.Character
if character then
camera.CameraType = Enum.CameraType.Custom --temp
camera.CameraSubject = character
end
until forcestop
Hmmm… The camera still tweens towards the player.
Why would I need to wait until the tween is completed?
Well, i don’t think you’d like tweens just straight up overriding another without that one not even completing itself…
Is this line necessary?
local tween = nil
Change it into local tween
, no nil or anything.
I had this issue once before as well with something and this fixed it: Try adding into your code a line that sets the camera subject to the players character.
I’m pretty sure I did that.
script.Parent.MouseButton1Click:Connect(function()
forcestop = true
if tween then
tween:Cancel()
tween:Cancel()
tween:Cancel()
tween:Cancel()
tween:Cancel()
end
camera.CameraType = Enum.CameraType.Custom
local character = workspace:FindFirstChild(player.Name)
if character then
camera.CameraSubject = character
end
script.Parent.Parent.Parent.Enabled = false
end)
It’s in this block as well, CameraSubject set to the player character.
Oh I didn’t see that, that’s strange
I edited my original post to have the current issue.
When I look at the camera’s properties (via workspace) during a tween, the subject is Humanoid.
What’s the difference between humanoid and character in this code? Would I need to make any changes?
In the start of the function, try changing the subject to be the part you want it to tween from
So in this case, camera1 variable.
The start of the TweenFunction, right?
Would I need to set the CFrame or anything? That’s what I’m doing in the rest of the function.
Thanks!
Yep, at the very start
Keep the code as the way it is but add the CameraSubject thing, if it still doesn’t work let’s try not setting the CFrame.
That’s funny… it tweens from camera1 to camera2, then goes BACK to camera1…
It doesn’t go to the player however, so I think we’re getting somewhere.
If I were to set the CFrame, would I keep the line with the CameraSubject, or replace it?
Why not make so the camera1 tweens to camera2, instead of the actual camera?
Then after the function ends, you can make so it goes back to it’s original place.