Hello ROBLOX DevFourm. I am making a recoil script for my gun. It works well while the player is standing still, however when I walk and shoot everything breaks. Help would be greatly appreciated.
Recoil Script
local function applyRecoil()
local elapsed = 0
local initialRotation = camera.CFrame
coroutine.wrap(function()
while elapsed < recoilDuration do
local deltaTime = task.wait()
elapsed = elapsed + deltaTime
local angleX = math.rad(math.random() * recoilIntensity+0.4)
local angleY = math.rad(math.random() * recoilIntensity)
local angleZ = math.rad(math.random() * recoilIntensity)
local recoilRotation = CFrame.Angles(angleX, angleY, angleZ)
camera.CFrame = initialRotation * recoilRotation
task.wait()
end
end)()
Video