Hello! I am currently writing a script using a combination of different videos/tutorials to have the players POV go to a security camera when they press E. Currently, I have it working so that when they press E, their POV goes to the security camera. My question is how would I go about making it so when they press E again, their view returns to normal? My code for what I have working is below and I’ve tried to solve my issue using what I currently know but have been unable to. Thanks!
local HumanoidRootPart = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
local UIS = game:GetService("UserInputService")
local button = game.Workspace.button
--Camera Script when E is pressed with 7 studs of button
UIS.InputBegan:connect(function(keyCode)
if keyCode.keyCode == Enum.KeyCode.E then
if(button.Position - HumanoidRootPart.Position).magnitude < 7 then
local myCamera = workspace.CurrentCamera
myCamera.CameraType = Enum.CameraType.Scriptable
local cameraPart = workspace.CameraPart
local xTilt = 0
local xMaxTilt = 2
local tiltSpeed = 0.05
while wait() do
myCamera.CFrame = cameraPart.CFrame * CFrame.Angles(0, math.rad(xTilt),0)
xTilt = xTilt + tiltSpeed
if (math.abs(xTilt) > math.abs(xMaxTilt)) then
tiltSpeed = tiltSpeed * -1
xMaxTilt = xMaxTilt * -1
end
end
end
end
end)