So I want to make if you click a button, your camera moved to a part, then if you press again, your camera get back to the player
But I find this problem:
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local button = script.Parent.Button
local looking = false
local endCFrame = game.Workspace.EventCamera.CFrame
local tweentime = 3
local debouncetime = 0.5
local active = false
button.MouseButton1Click:Connect(function()
if active then return end active = true
looking = not looking
if looking then
button.Text = "Go Back!"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
camera.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(camera, TweenInfo.new(tweentime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out,0,false,0), {CFrame = endCFrame}):Play()
wait(tweentime+debouncetime)
else
button.Text = "See Timer!"
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
game.TweenService:Create(endCFrame, TweenInfo.new(tweentime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out,0,false,0), camera):Play() --The problem
camera.CameraType = Enum.CameraType.Custom
wait(debouncetime)
end
active = false
end)
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local button = script.Parent.Button
local looking = false
local endCFrame = game.Workspace.EventCamera.CFrame
local tweentime = 3
local debouncetime = 0.5
local active = false
local cameraCFrame
button.MouseButton1Click:Connect(function()
if active then return end active = true
looking = not looking
if looking then
cameraCFrame = camera.CFrame
button.Text = "Go Back!"
player.Character.Humanoid.WalkSpeed = 0
player.Character.Humanoid.JumpHeight = 0
camera.CameraType = Enum.CameraType.Scriptable
game.TweenService:Create(camera, TweenInfo.new(tweentime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out,0,false,0), {CFrame = endCFrame}):Play()
wait(tweentime+debouncetime)
else
button.Text = "See Timer!"
player.Character.Humanoid.WalkSpeed = 16
player.Character.Humanoid.JumpHeight = 7.2
game.TweenService:Create(camera, TweenInfo.new(tweentime, Enum.EasingStyle.Sine, Enum.EasingDirection.Out,0,false,0), {CFrame = cameraCFrame}):Play() --The problem
camera.CameraType = Enum.CameraType.Custom
wait(debouncetime)
end
active = false
end)