Timer error , doesn't recognize argument

[lua]
function Sprint( pl )
local Run = IsRunning( pl )

if Run then
	Power = math.Clamp( Power - 1, 0, 100 )
else Power = math.Clamp( Power + 1, 0, 100 )
end
pl:SetRunSpeed( Power + 220 )	
pl:setNWInt( "run_power", Power )

end
timer.Create( “timer”, 1, 0,Sprint,pl)
[/lua]

What it’s supposed to do is drain run energy when you sprint and replenish it when you’re not running. Timer should run it every one second, but I get a nice error every second.

Timer Error: SandboxModded/gamemode/init.lua:97: attempt to index local ‘pl’ (a nil value)

Don’t know what the fuck is wrong with it, I think the Timer.Create function is broken. Anyone have any insight into this?

Passing an argument called pl to the timer will not magically make it reference a player entity. You need to get the player object yourself. It seems you are running this on the server and would like this to run for every player, if so you can do this:
[lua]timer.Create(“timer”, 1, 0, function()
for _, pl in ipairs(player.GetAll()) do
local Run = IsRunning( pl )
if Run then
Power = math.Clamp( Power - 1, 0, 100 )
else
Power = math.Clamp( Power + 1, 0, 100 )
end
pl:SetRunSpeed( Power + 220 )
pl:setNWInt( “run_power”, Power )
end
end)[/lua]

[editline]10:14PM[/editline]

1000 posts yay!