I currently have a script written down below that is in charge of sprinting and camera shake. As of right now when you press “c” it locks you in first person and when you press “c” again it takes you out. And the camera shake works perfectly, it doesn’t shake when you’re not in first person and it shakes when you are. But now the problem is, if you go into first person and start sprinting, the camera shake works, but once you go back out of first person, the camera shake keeps going. Any help is appreciated, thanks!
Here’s a video on what’s happening,
local script in StarterCharacterScripts vvv
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local hum = script.Parent:WaitForChild('Humanoid')
local firstperson = false
sprinting = false
UIS.InputBegan:Connect(function(input, processed)
if sprinting == false and input.KeyCode == Enum.KeyCode.LeftShift then
sprinting = true
hum.WalkSpeed = 20
end
UIS.InputEnded:Connect(function(input)
if sprinting == true and input.KeyCode == Enum.KeyCode.LeftShift then
sprinting = false
hum.WalkSpeed = 12
end
end)
if firstperson == false and input.KeyCode == Enum.KeyCode.C and not processed then
firstperson = true
player.CameraMode = Enum.CameraMode.LockFirstPerson
elseif firstperson == true and input.KeyCode == Enum.KeyCode.C and not processed then
player.CameraMode = Enum.CameraMode.Classic
firstperson = false
end
if firstperson == true then
local runService = game:GetService('RunService')
local char = script.Parent
local function updateShake()
local currentTime = tick()
if hum.MoveDirection.Magnitude > 0 then
if sprinting == true then
local bobbleX = math.cos(currentTime * 10) * 1
local bobbleY = math.abs(math.sin(currentTime * 10)) * 1
local bobble = Vector3.new(bobbleX, bobbleY, 0)
hum.CameraOffset = hum.CameraOffset:lerp(bobble, .25)
elseif sprinting == false then
local bobbleX = math.cos(currentTime * 7) * .5
local bobbleY = math.abs(math.sin(currentTime * 7)) * .5
local bobble = Vector3.new(bobbleX, bobbleY, 0)
hum.CameraOffset = hum.CameraOffset:lerp(bobble, .25)
end
else
hum.CameraOffset = hum.CameraOffset * .75
end
end
runService.RenderStepped:Connect(updateShake)
end
end)