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
    end
    if Stamina <= 0 then
        DarkRP.Notify("You have ran out of Stamina, please rest.")
        local function StaminaCountUp()
            Stamina = Stamina + 10
        end
        timer.create("stamniagoup",2,0,StaminaCountUp)
	Darkrp.Notify("Your stamina is regaining")
    end
    if Stamina == 100 then
        timer.Remove("staminagoup")
    end
end
hook.Add("KeyPress","StaminaControl",StaminaControl) 

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

http://wiki.garrysmod.com/page/GM/PlayerButtonDown

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