A completely unrelated tip is to replace how you are fetching the player’s Ped object. The more optimized method is like so:
local ped = PlayerPedId()
Why this is so and more info can be found on this helpful post here: [Question] Difference between GetPlayerPed(-1) and PlayerPedId()
Goodluck!