Thx you so mutch, all of your info has helped me.
So the solution is :

Function play/stop with button

function playAnim(data)
    local ped = GetPlayerPed(-1)
    if data.types == "animsAction" then
        if IsEntityPlayingAnim(ped, data.anim.lib, data.anim.anim, 3) then
            ClearPedTasksImmediately(ped)
            return
        end
        RequestAnimDict(data.anim.lib)
        while not HasAnimDictLoaded(data.anim.lib) do
        Citizen.Wait(0)
        end
        if HasAnimDictLoaded(data.anim.lib) then
            TaskPlayAnim(ped,data.anim.lib,data.anim.anim ,8.0, -8.0, -1, 0, 0, false, false, false )
        end
    elseif data.types == "animsActionScenario" then
        if IsPedUsingScenario(ped, data.anim.anim) then
            ClearPedTasksImmediately(ped)
            return
        end
        TaskStartScenarioInPlace(ped, data.anim.anim, 0, false)
    end
end

function cancel when player move

Citizen.CreateThread(function()
	  	while true do
		    Citizen.Wait(0)
                 if IsPedUsingAnyScenario(GetPlayerPed(-1)) then
                     if IsControlPressed(0, 32) or IsControlPressed(0, 33) or IsControlPressed(0, 34) or                         IsControlPressed(0, 35) or IsControlJustPressed(1, 8) or IsControlJustPressed(1, 9) then
                          ClearPedTasks(GetPlayerPed(-1))
                     end
                 end
		end
	end)
2 Likes