I've made code so that after tapping E or Q, the movement naturally slows down, but after it does, it continues going the opposite direction and starts speeding up.

local UserInputService = game:GetService("UserInputService")
local player = game.Players.LocalPlayer;
local char = player.Character or player.CharacterAdded:wait();
local bodyAngularVelocity  = Instance.new("BodyAngularVelocity")
bodyAngularVelocity.AngularVelocity = Vector3.new(0,0,0)
bodyAngularVelocity.Parent = char.Torso

UserInputService.InputBegan:connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.E and not gameProcessed then
        bodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, -2)
    end
end)

UserInputService.InputEnded:connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.E and not gameProcessed then
        while true do
			if bodyAngularVelocity.AngularVelocity ~= Vector3.new(0,0,0) then
			char.Torso.BodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, char.Torso.BodyAngularVelocity.AngularVelocity.Z + 0.05)
		   wait()
			else
				bodyAngularVelocity.AngularVelocity = Vector3.new(0,0,0)
			end
			wait()
		  end
    end
end)

UserInputService.InputBegan:connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.Q and not gameProcessed then
        bodyAngularVelocity.AngularVelocity = Vector3.new(0, 0,  2)
    end
end)

UserInputService.InputEnded:connect(function(input, gameProcessed)
    if input.KeyCode == Enum.KeyCode.Q and not gameProcessed then
        while true do
			if bodyAngularVelocity.AngularVelocity ~= Vector3.new(0,0,0) then
			char.Torso.BodyAngularVelocity.AngularVelocity = Vector3.new(0, 0, char.Torso.BodyAngularVelocity.AngularVelocity.Z - 0.05)
		   wait()
			else
				bodyAngularVelocity.AngularVelocity = Vector3.new(0,0,0)
			end
			wait()
		  end
    end
end)

I would be extremely grateful if i could be corrected or told what the issue is, and how to fix it.

Thanks.