RunConsoleCommand somehow doesn't load

I’m working on a stamina system. Somehow the RunConsoleCommand doesn’t make the play go to 500 runspeed.

cl_init:
[lua]
local running = false
local stamina = 50

function staminaKeyPress( ply, key )
if key == IN_SPEED then
running = true
drain()
end
end
hook.Add( “KeyPress”, “staminaKeyPress”, staminaKeyPress )

function staminaKeyRelease( ply, key )
if key == IN_SPEED then
running = false
staminaReg()
end
end
hook.Add( “KeyRelease”, “staminaKeyRelease”, staminaKeyRelease )

function drain()
timer.Create( “MinusStamina”, 1, 0, function()
if running == true then
stamina = stamina - 5
if stamina <= 0 then
RunConsoleCommand( “out_of_stamina” )
end
end

	if running == false then
		timer.Stop( "MinusStamina" )
	end
end)
timer.Start( "MinusStamina" )

end

function staminaReg()
timer.Create( “PlusStamina”, 1, 0, function()
if running == false then
stamina = stamina + 1
end
end)
timer.Start( “PlusStamina” )
end
[/lua]

init:

[lua]
function OutOfStamina( ply )
ply:SetRunSpeed( 500 )
end
concommand.Add( “out_of_stamina”, OutOfStamina )
[/lua]

I’ll have to go for the night, but I’ll check on tomorrow.

Your stamina code isn’t setting the run speed anywhere except when it ends. IIRC, the regular run speed is 500, so it wouldn’t make a difference. Have you tried setting the value to something extremely low or extremely high to test it? Did you make sure that your condition is being met?

If you set the player speed in those functions, don’t forget that your concommand won’t work unless you unset those hooks or just establish the same ‘if stamina <= 0’ check before they run. If you don’t, your command will run for a tick, but will then be overridden when someone presses the keys you’ve hooked.

Lol my bad, I thought 500 was walking speed. Though I got another question:

[lua]
timer.Create( “PlusStamina”, 1, 0, function()
if running == false || stamina < maxstamina then
stamina = stamina + CFGstaminaReg
end
end)
[/lua]

I want it to stop when stamina reaches maxstamina, though it doesn’t seem to work.

Change your ‘OR’ to ‘AND’. You want the player to be stopped and stamina to be lower than max, right? With the ‘OR’, the conditional will return true for either condition.

Yes, you were right. It works now, thanks.