I’m trying to make it so that if the player clicks a button, it sets the camera type to the player camera, so that the tween stops running, and the camera type is no longer scriptable.
Here’s my code:
script.Parent.MouseButton1Click:Connect(function()
local camera = game.Workspace.Camera
camera.CameraType = Enum.CameraType.Custom
script.Parent.Parent.Parent.Enabled = false
end)
Another script is animating the camera too, could that be causing the issue?
Summary
local TweenService = game:GetService("TweenService")
local cams = game.Workspace.Cameras
local done = false
local camera = game.Workspace.Camera
local sceneTime = 20
local tweeninfo = TweenInfo.new(
sceneTime,
Enum.EasingStyle.Sine,
Enum.EasingDirection.Out,
0,
true,
0
)
function tween(camera1, camera2, ending)
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = camera1.CFrame
local tween = TweenService:Create(camera, tweeninfo, {CFrame = camera2.CFrame})
tween:Play()
wait(sceneTime)
if ending then
camera.CameraType = Enum.CameraType.Custom
end
end
tween(cams.Camera1, cams.Camera2, false)
--wait(20)
tween(cams.Camera3, cams.Camera4, false)
--wait(20)
tween(cams.Camera5, cams.Camera6, false)
--wait(20)
tween(cams.Camera7, cams.Camera8, false)
--wait(20)
tween(cams.Camera9, cams.Camera10, true)
Why would this not work?
Would I also have to stop the other script (with the camera tweens) If so, then how would I accomplish that?
Thanks!
EDIT: My new issue is that the camera tweens to the player, instead of teleporting to another camera.
I’m starting to think it’s the other script’s issue, as the UI does disappear, but they camera doesn’t get set.
Is there a way to make it (the other camera animation) reset/stop? The button script is a LocalScript in StarterGui and the camera tween is a LocalScript inside StarterPlayerScripts.
If you’re currently in Studio, can you test play and try going to the properties in Workspace => Camera => CameraSubject, and change the CameraSubject to your character after your tween is finished and see if it works?