Check if player is running

How would I check if a player is currently running?


hook.Add("Move", "UniqueHookName", function(ply, move)
	if move:KeyDown(IN_SPEED) then
	--your stuff here

Thank you I Will try now. But how would I disable running(Im making a stamina system) Thanks

Whenever they should not able to run, you could put the run speed to the same as walk speed.

I Have done that Thanks. But the whole things tthe other guy wrote to check if I was running I dont understand. I Tought there would be something like LocalPlayer():IsRunning()

if ply.Stamina <= 0 then

or something like this. Please don’t use hardcoded values, so it is adaptable to other gms and so on.

[lua]hook.Add(“Move”, “UniqueHookName”, function(ply, move) – The Hook is called everytime an player moves.

if move:KeyDown(IN_SPEED) then -- Check if the Key Pressed is the Sprint Key (IN_SPEED)
--your stuff here


Yeh I have set the run and walk speed as a variable in the teams , so I can just do it that and and if it gets modified it will all update :slight_smile: But Thanks for the help. Anyway is there an easier way to check if the player is running?

Also how do I get a players teams Using Team() on a clientside script. Like LocalPlayer():Team() As i get an error for it

[editline]24th October 2014[/editline]

Here is the error too

[ERROR] gamemodes/thedarkestdays/gamemode/cl_init.lua:18: attempt to call method ‘Team’ (a nil value)

  1. v - gamemodes/thedarkestdays/gamemode/cl_init.lua:18
  2. unknown - lua/includes/modules/hook.lua:84

Use this to check the players team == the right team

If LocalPlayer():Team() == teamname/teamid

Those aren’t good ways to detect if the player is running. I started working on an example for a stamina system ( with a student who wanted to go back to it later after working out a few easier things ) which will provide insight:

This is where the lesson stopped:

So basically if you hold the shift key and are not moving, it’ll count it as sprinting with the above in this thread method. But, if you grab the walk-speed and determine if player is moving faster, then you have a reliable method for detecting “sprinting / running”. You can also return the 0-1 value in terms of speed OVER walk-speed to max-speed-possible-while-running to determine how much energy to burn, or whatever…

The part where we do the calculation to grab the modifier of x speed OVER walk-speed to max-speed-while-running to calculate energy consumption, etc, is in the next part of the lesson.

darkmist, if you want to review the part of the chat-log that covers stamina systems and covers a lot of the mechanics ( which are in the file above and beyond that file ), feel free to add me on Steam.


Why am I getting this error? [ERROR] gamemodes/thedarkestdays/gamemode/cl_init.lua:3: attempt to call method ‘Team’ (a nil value)

  1. unknown - gamemodes/thedarkestdays/gamemode/cl_init.lua:3