Timer.Create Issues

Hey there, LUA noob here.

been trying to make a timer that increases player speed gradually but am stuck on an error - bad argument #4 to ‘Create’ <function expected, got nil>

anyway here is my code, please help me with what ever you can and tell me where I went wrong? =)


timer.Create("Weightloss", 30, 0, Weightloss, ply )

function Weightloss( ply )
PrintMessage( HUD_PRINTCENTER, "Fatboy has lost some weight, He's speeding up!" )	
	if ply:Team()== 1 then
		ply:SetWalkSpeed(ply:GetWalkSpeed() + 15)
	end
end

  1. You are using the timer function improperly.
  2. You are defining the function AFTER you create the timer that uses the function.
  3. “ply” looks like undefined variable to me.

So, correct code would be:




function Weightloss( ply )
PrintMessage( HUD_PRINTCENTER, "Fatboy has lost some weight, He's speeding up!" )    
    if ply:Team()== 1 then
        ply:SetWalkSpeed(ply:GetWalkSpeed() + 15)
    end
end

timer.Create("Weightloss", 2, 0, function() for id, p in pairs(player.GetAll()) Weightloss( p ) end end )



Thank you man so much! and for telling me where I went wrong =)