Ammo regen help

How would i make it regen ammo for this code i made:


function AmmoReq ( ply )
local wep = ply:GetActiveWeapon()
local checkammo = ply:GetAmmoCount ( wep:GetPrimaryAmmoType() )

if ply(IsValid) then
timer.Create("AmmoReqTimer"..ply:UniqueID, 3, 0, function()
	-- How would i check both locals above and then make it give ammo
end)
hook.Add( "PlayerSpawn", "Ammo Req Check", AmmoReq)

[LUA]timer.Create(“AmmoReqTimer”…ply:UniqueID, 3, 0, function()
if checkammo < 256 then
ply:GiveAmmo( 1, wep:GetPrimaryAmmoType(), true )
end
end)[/LUA]

I’d also recommend running another valid checker inside of the timer, that way it cannot return NULL if the player is dead during a tick, or has no weapon.