Run code when player spawns (and VGUI can be called) for the first time in their session


I’m working on some code.

I have a hook with PlayerInitialSpawn to run a net message to the client to open some vgui, only problem is that it doesn’t open and gives an error (because PlayerInitialSpawn is ran at “Sending Client Info”). How would I run it when the player is in the actual game within their session?


Put it on a timer for 1 second. That works for me.

there’s probably some way to check if a player is fully validated into the game dunno how though

Here’s an example of it:

It sends to clients, creates the HUDPaint hook, and the timer will only start when the player is fully connected ( because HUDPaint is only called when the player can view the screen and fully connected ). For non-important tasks, this can be used to detect when a player is fully connected. For important things, you’d want a server-side hook that will detect when the player is fully connected such as this:

The problem with the one second timer is one, there’s gonna be a delay for some people between the GUI popup and their spawn, and two, slow computers sometimes take more than a second to get from sending client info to in-game.

vgui != hudpaint

So, remove the HUDPaint hook the first time it is run ( which means the player is fully in the game ) instead of allowing it to run until count is done, open the VGUI and be done with it. Or use PlayerFullyConnected hook I pasted to have it verified by the server ( if it is something important )

Either way, it is the same concept of what the topic creator was looking for.

That makes sense haha… thanks.

That is WAY more hacky then it needs to be. Just hook into OnEntityCreated.

I am pretty sure PlayerInitialSpawn is called when the player has already spawned into the server, it happens just about when player is sending client info or receiving server info, so the player object should already be existing. ( That’s why you get the shitty ULX MOTD when loading. )

It is after the entity was already created server-side though, client is still loading the clientside lua.

Why do you need LocalPlayer to create some panels? You can send all the required info with a net message and create the panel from the net message on client.

I already tried sending a net message on PlayerInitialSpawn, just errored-out with no menu (i also had F4 hooked up to show menu), however when i pressed F4 it was there, so it was the net message. I ended up doing what Acecool said, and it worked.