[HELP] Cancel animation on keypress

I’m trying to make an emote command which cancels on keypress (WASD)
But it never recognizes my inputs…

I have tried:
if IsControlPressed(1, ) then
ClearPedTasksImmediately()
ClearPedTasks()
ClearPedSecondaryTask()

and neither of them work…
I even tried setting the animation timer to 1, but nothing happens…
Am I setting up the controlpressed wrong?

Source: https://pastebin.com/Z6wJhna3

1 Like

You need to poll the IsControlPressed in a loop.

@mraes And how would I do that? Very new to lua…

Look the other scripts. IsControlJustPressed say yes or no basically, so here you are verifying just once, then the script go to next line… Here you need to make a loop as @mraes suggest.
so :

 Citizen.CreateThread(function()
        while true do (and always a Wait(0) after that)
            Wait(0)
            if IsControlJustPressed(1, 86) then
                 -- Clear task stuff here
            end
        end 
 end)

The CreateThread is called when a fram is generated (more or less, correct me if I’m wrong)
So it’s called, then you put that in a loop and that’s all.
I can’t suggest you more and more to get a look on the other scripts, this will learn you the basics, the things you always need :slight_smile:
Good luck !

@Izio_Romain
Got it working finally, tried the createthread function before, but never got it working…
Changed your ‘Keys’ to ‘86’ instead and it worked like a charm! (Y)