Help on a stamina script

So right now i’m trying to make it so that when you click your primary attack button, your stamina number is subrtracted by 10. Then if your stamina number is set to 0, you get a notification that says you have lost all your stamina, and to try and rest. If anyone knows how to force the player from attacking until they have more than or equal to 1 stamina, please help with that as well. My main problem though is just seeing what I need to use to detect when they use their primary attack.

 local Stamina = 100

 for k,v in pairs(player.GetAll()) do
		if(v:KeyDown(IN_ATTACK)) then
        Stamina = Stamina - 10
    if Stamina <= 0 then
        DarkRP.Notify("You have ran out of Stamina, please rest.")
        local function StaminaCountUp()
            Stamina = Stamina + 10
	Darkrp.Notify("Your stamina is regaining")
    if Stamina == 100 then

One thing I would like to note is that I do know that pairs is more for moving, but I have already tried Ply:KeyPressed(IN_ATTACK), but it didn’t really work.

you could use this hook and check which button has been pressed and then just prevent the press if stamina = 0

Firstly, there’s no need to use PlayerButtonDown, that doesn’t tell you the button as KeyPress does. Secondly, it’s timer.Create (with a capital C). Thirdly, you don’t appear to even have a function called StaminaControl

There’s no need to loop through every player every time a KeyPress hook gets called, just use the Player argument it has