How to run Lua from the console in GMod
Type lua_run print(#player.GetAll()) in the server console to run that line of Lua on the server at once; this one prints the player count.
lua_run
Runs a line of Lua code on the server, from the server console or RCON.
lua_run <code> Examples
lua_run print(#player.GetAll()) Print the number of connected players.
lua_run for _, p in ipairs(player.GetAll()) do p:SetHealth(100) end Heal everyone to 100.
Arguments
codeRequired- Lua code to run on the server.
What it does
Executes the given Lua in the server realm right away, which is handy for quick checks, fixes and testing without writing a file. Everything after the command is treated as code, so quotes around it are optional.
The game's own description: Run a Lua command
Good to know
- Players cannot use it on a dedicated server, only the server console and RCON can.
- Errors print to the server console.
Run it on your server
On a SLASHPLAY server, type it in the Console tab of the server page; the reply shows right under it. A value set there lasts until the server restarts. To keep it, add the line to garrysmod/cfg/server.cfg. New to this? Start a GMod server first.
Your own
GMod server.
From $0.03 an hour, only while it runs. New accounts get 6 free tokens.