Ammo regeneration

Im making a function that refills your ammo on active weapon every 60 secons (10 seconds when i debug).

timer.Create( "RefillAmmo", 10, 0,RefillAmmo())
function RefillAmmo()
local Wpn = ""
local Count = 0
    for k , v in ipairs(player.GetAll()) do
    Wpn = v:GetActiveWeapon():GetPrimaryAmmoType()
    Count = v:GetAmmoCount()
    v:SetAmmo(Count + 30, Wpn)

i get this error “Timer Error: attempt to call a nil value”

You don’t need the brackets (parentheses) in the timer.Create function, at the moment you are passing the return value of RefillAmmo to the timer, not the actual function.


[lua]timer.Create( “RefillAmmo”, 10, 0,RefillAmmo) [/lua]

First of all, the syntax for the timer is

timer.Create( "RefillAmmo", 10, 0, RefillAmmo )


Secondly, your ammo thing won’t work because SetAmmo uses a string ammo type whereas GetPrimaryAmmoType returns an integer.

GetPrimaryAmmoType returns a string.



Thanks both of you
and thank you MakeR again

You’re welcome.

] lua_run_cl print(LocalPlayer():GetActiveWeapon():GetPrimaryAmmoType())


@Entoros the script is already working but thanks anyway

You must have overridden it somewhere.