The code for this script does work, it’s just I would like the player to be able to move the camera while it’s running. Is there anyone that can help out?
local Camera = workspace.Camera
local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local originalCFrame = Camera.CFrame
local function applyShake(intensity, range, nonshakability, t)
local clamp = math.clamp(1 + (intensity - 0.1)*(1-(nonshakability/range)), 0.1, intensity)
local pos = originalCFrame.Position
local rotX = (math.noise(t, clamp) - 0.5) * clamp / 30
local rotY = (math.noise(t + 100, clamp) - 0.5) * clamp / 30
local rotZ = (math.noise(t + 200, clamp) - 0.5) * clamp / 40
Camera.CFrame = CFrame.new(pos) * CFrame.Angles(rotX, rotY, rotZ)
end
game.ReplicatedStorage.CameraShake.OnClientEvent:Connect(function(intensity, range, nonshakability, duration)
local nonshakabilityValue = game.Workspace:FindFirstChild("NonShakability")
if nonshakabilityValue and nonshakabilityValue:IsA("ValueBase") then
nonshakability = nonshakabilityValue.Value
end
originalCFrame = Camera.CFrame
local startTime = os.clock()
while os.clock() - startTime < duration do
local t = os.clock()
applyShake(intensity, range, nonshakability, t)
task.wait(0.015)
end
local transitionDuration = 0.3
local transitionStart = os.clock()
local currentCFrame = Camera.CFrame
local pos = originalCFrame.Position
while os.clock() - transitionStart < transitionDuration do
local alpha = (os.clock() - transitionStart) / transitionDuration
local currentRot = currentCFrame - currentCFrame.Position
local originalRot = originalCFrame - originalCFrame.Position
local lerpedRot = currentRot:Lerp(originalRot, alpha)
Camera.CFrame = CFrame.new(pos) * lerpedRot
task.wait(0.015)
end
Camera.CFrame = originalCFrame
end)