Well to help this is a simple mistake, you first need to not do such a chunky code block and make it smaller to have the code not get tied up with risking a jitter the player can notice, and may end up having the parts of your player's body get out of place for a frame and then bug out to get even worse!
Avoid big code and use the more built-in ROBLOX locking mouse, that's already shift lock code, made for you! And ROBLOX actually really already has plugins for all of this so using that you can easily take that and edit it, if you want to, aides, ROBLOX is full of over 2M games using those plugins and I bet you'll find something that works for you!