How to make a command run on startup

How would I have a command run the moment the player joins the server?

I want the player to see a menu the moment he spawns, this is the command: lua_run_cl CreateCharacterWindow()

Wouldn’t it be easier to call the function without any commands?

hook.Add(“InitPostEntity” , “Delay until all entities are created” , CreateCharacterWindow)

When he first joins the server? Do this in init.lua:
function GM:PlayerInitialSpawn( pl )
RunConsoleCommand( “Command Name” )

Or when he spawns every time:
function GM:PlayerSpawn( pl )
RunConsoleCommand( “Command Name” )

Best to use pl:ConCommand so it doesn’t send it to all players everytime. :wink:

That code wouldn’t even work, as it’s server-side. RunConsoleCommand would run the command on the server, not the clients.

Best way to do what you want is this.
[lua]hook.Add( “OnEntityCreated”, “OpenCharMenu”, function( ent )
if ent:IsValid() and ent == LocalPlayer() then
end )[/lua]

Completely client-side.

You don’t even read do you, was talking about pl:ConCommand not RunConsoleCommand… it would work because your sending the command to the player from the server, as long as the concommand.Add(“Command Name”) is valid. :wink:

InitPostEntity :eng101:

Sorry, I quoted the wrong post :eng99:
But you were still wrong, RunConsoleCommand server-side would just run the command on server, not send it to all clients like you said.


I didn’t know that works and I missed your first post, cool :v:

You’re wrong, i wasn’t talking about Running an console command server side, i was talking about using the pl:ConCommand serverside.

I quoted his post period.

In the code you quoted, wakeboarder used RunConsoleCommand server-side.

In your post,

you’re implying that RunConsoleCommand sends it to all players if it’s called.

I don’t see where I’m wrong.

Kids, kids… You’re both right.

I’m older than you :haw:

Enough derailing now. OP, use Flapjack’s solution in the first reply.

Probably. Im 16.