Print Output Once

I am making an afk script and I am trying to get it to output to the chat when a player goes afk and when the player returns but it seems to output the text many times. Can someone fix this?

Note: This is something someone whipped up for me a long time ago and I am getting back into lua so I am still relearning.
AwayTime = 300 // seconds. (300 = 5 min)

function AFK()
for _, v in pairs( player.GetAll()) do
local a = (v:GetNWInt(“LA”) + AwayTime) - CurTime()
if a <= 0 then
v:SetNWBool(“AFK”, true)
if v:GetNWBool(“AFKN”) == true then
for k, ply in pairs( player.GetAll( ) ) do
ply:PrintMessage( HUD_PRINTTALK, v:Nick() … " is now AFK." )
v:SetNWBool(“AFKN”, false)
timer.Create(“AFK_timer”, 1, 0, AFK)

function ResetAFK(ply)
if ply:GetNWBool(“AFK”) == true then
for _, v in pairs( player.GetAll()) do
v:PrintMessage( HUD_PRINTTALK, ply:Nick() … " is no longer AFK." )
ply:SetNWInt(“LA”, CurTime())
ply:SetNWBool(“AFK”, false)
ply:SetNWBool(“AFKN”, true)

hook.Add( “KeyPress”, “KeyPressed”, ResetAFK )
hook.Add( “KeyRelease”, “KeyReleased”, ResetAFK )
hook.Add( “PlayerInitialSpawn”, “PlayerInitialSpawn”, ResetAFK )

Does it spam “is now AFK” or “is no longer AFK”?

It seems to output it three times when it should only be outputted once.

remove hook.Add( “KeyPress”, “KeyPressed”, ResetAFK )

After swapping and using only one of the three hooks at a time it still prints out the message twice now instead of three, I got this working a long time ago but lost it and can’t remember how I did it :frowning: