Help stopping an animation

I have this as stopping it

RegisterNetEvent('event:event')
AddEventHandler('event:event', function(t)
    local id = GetPlayerFromServerId(t)
    cuffedplayers[id] = false
    if IsPedUsingAnyScenario(id) then
        Citizen.Wait(5)
        ClearPedTasks(id)
        StopAnimTask(id, 'mp_arresting', 'idle', 1.0)
    end
end)

I have this as starting it

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        for i,j in pairs(cuffedplayers) do
            if j == GetPlayerPed(-1) then
                if IsPedArmed(GetPlayerPed(-1), 7) then
                    SetCurrentPedWeapon(GetPlayerPed(-1), 0xA2719263, true)
                end
                DisableControlAction(1, 18, true)
                DisableControlAction(1, 24, true)
                DisableControlAction(1, 69, true)
                DisableControlAction(1, 92, true)
                DisableControlAction(1, 106, true)
                DisableControlAction(1, 122, true)
                DisableControlAction(1, 135, true)
                DisableControlAction(1, 142, true)
                DisableControlAction(1, 144, true)
                DisableControlAction(1, 176, true)
                DisableControlAction(1, 223, true)
                DisableControlAction(1, 229, true)
                DisableControlAction(1, 237, true)
                DisableControlAction(1, 257, true)
                DisableControlAction(1, 329, true)
                DisableControlAction(1, 80, true)
                DisableControlAction(1, 140, true)
                DisableControlAction(1, 250, true)
                DisableControlAction(1, 263, true)
                DisableControlAction(1, 310, true)
                DisableControlAction(1, 37, true)

                DisableControlAction(1, 22, true)
                DisableControlAction(1, 55, true)
                DisableControlAction(1, 76, true)
                DisableControlAction(1, 102, true)
                DisableControlAction(1, 114, true)
                DisableControlAction(1, 143, true)
                DisableControlAction(1, 179, true)
                DisableControlAction(1, 193, true)
                DisableControlAction(1, 203, true)
                DisableControlAction(1, 216, true)
                DisableControlAction(1, 255, true)
                DisableControlAction(1, 298, true)
                DisableControlAction(1, 321, true)
                DisableControlAction(1, 328, true)
                DisableControlAction(1, 331, true)
                DisableControlAction(0, 63, false)
                DisableControlAction(0, 64, false)
                DisableControlAction(0, 59, false)
                DisableControlAction(0, 278, false)
                DisableControlAction(0, 279, false)
                DisableControlAction(0, 68, false)
                DisableControlAction(0, 69, false)
                DisableControlAction(0, 75, false)
                DisableControlAction(0, 76, false)
                DisableControlAction(0, 102, false) 
                DisableControlAction(0, 81, false)
                DisableControlAction(0, 82, false)
                DisableControlAction(0, 83, false)
                DisableControlAction(0, 84, false)
                DisableControlAction(0, 85, false)
                DisableControlAction(0, 86, false) 
                DisableControlAction(0, 106, false)
                DisableControlAction(0, 25, false)
            end
            while not HasAnimDictLoaded('mp_arresting') do
                RequestAnimDict('mp_arresting')
                Citizen.Wait(5)
            end
            if not IsEntityPlayingAnim(GetPlayerPed(i), 'mp_arresting', 'idle', 3) then
                TaskPlayAnim(GetPlayerPed(i), 'mp_arresting', 'idle', 8.0, 1.0, -1, 49, 1.0, 0, 0, 0)
            end
        end
    end
end)

The cutting works and set them to being cuffed to false, but it just goes back into playing the cuffed animation.

That’s because you’re putting everyone from the cuffedplayers table in cuffs every tick. (You’re never checking if their values inside the cuffedplayers table is set to true)

You’ll need to make sure that when that code is executed, it only triggers for players inside the cuffedplayers.

One way to fix this is to modify your event:

instead of setting cuffedplayers[id] to flase, try removing the id instead: cuffedplayers[id] = nil

Just figured out it’s this check thats giving me problems

Citizen.CreateThread(function()
    while true do
        Citizen.Wait(0)
        for i,j in pairs(cuffedplayers) do
            if j == GetPlayerPed(-1) then