So, I have this script where, when you press the button it shifts the camera to an object, and then of course there is another button to shift it back to its original object. Problem is, after I’ve pressed these buttons, the play button doesn’t return the camera back to the player.
I’ve tried every solution I could think of, but also, the script is pretty old and bad.
I’m wondering if there’s a better way to do this and, a way to fix this problem?
Here’s the script:
local camera = game.Workspace.Camera
local play = script.Parent.Parent.Play
local player = game.Players.LocalPlayer
local amount = 999999
local function cameraTween()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.Cameras.Cam3.CFrame
local info = TweenInfo.new(amount,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = TweenService:Create(camera,info,{CFrame = game.Workspace.Cameras.Cam3.CFrame})
tween:Play()
end
script.Parent.MouseButton1Click:Connect(function()
workspace.SFX["button.wav"]:Play() -- sound effects
cameraTween()
play.Active = true
script.Parent.Visible = false
end)
That’s the camera that shifts it back to its original object
Here’s the play button script:
local camera = game.Workspace.Camera
script.Parent.MouseButton1Click:Connect(function()
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = player.Character.Head.CFrame
end
If you need any more information, let me know.
I’ve tried doing this with events, but I realized that I can’t because everything is on a local script.
local camera = game.Workspace.Camera
local play = script.Parent.Parent.Play
local player = game.Players.LocalPlayer
local amount = 999999
local bindableEvent = --where your bindableEvent is
local function cameraTween()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = game.Workspace.Cameras.Cam3.CFrame
local info = TweenInfo.new(amount,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)
local tween = TweenService:Create(camera,info,{CFrame = game.Workspace.Cameras.Cam3.CFrame})
tween:Play()
end
script.Parent.MouseButton1Click:Connect(function()
workspace.SFX["button.wav"]:Play() -- sound effects
cameraTween()
play.Active = true
script.Parent.Visible = false
bindableEvent:Fire()
end)
and for the play button script:
local camera = game.Workspace.Camera
local bindableEvent = --where your bindableEvent is
bindableEvent.Event:Connect(function()
camera.CameraType = Enum.CameraType.Custom
camera.CFrame = player.Character.Head.CFrame
end
I would also put the BindableEvent somewhere in the starterPlayer or starterPlayerScripts.
When the play button is pressed the tween is still playing, so once you change the CFrame it will be changed back straight away. Try stopping the tween using tween:Pause() when the play button is pressed.