I current have this code in a localscript and it makes your camera shake. It starts shaking and should shake less and less as the function runs more. When shakeMax is lower than 1 it should disconnect the function and therefore stop the shaking. However, it doesnt always disconnect, sometimes it keeps printing ‘done shaking’ for every time the function runs. What causes this and how do i solve it?
local shakeMin = 0
local shakeMax = 400
local drop = 0.21
loop = game:GetService('RunService').RenderStepped:connect(function()
if shakeMax > 1 then
game.Players.LocalPlayer.Character.Humanoid.CameraOffset = Vector3.new(math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000)
shakeMax = shakeMax - drop
else
loop:Disconnect()
print('done shaking')
end
end)