when player spawns.

how do i make a piece of code execute when the player spawns for the first time? i heard of ply:InitialSpawn but am currently unable to use it correctly.
thanks in advance

This is for the first time they connect.


function FirstSpawn( ply )
 
	ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
 
end
 
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )

Note that if you’re defining it in your gamemode’s files you can write it this way :


function GM:PlayerInitialSpawn( ply )
 
	ply:PrintMessage(HUD_PRINTCENTER,"Welcome to the server!")
 
end

This is for everytime they spawn :

ok so just to clarify, i can get it to read the information of the player from a .txt file with that function?

You can do the reading/writing of information at any point. So yeah if you make a function to retrieve and set information there nothing’s stopping you. I do suggest you use player data tough, a lot simpler and will stay between connections. And NWInt to keep it during a session.

example :


function Money( ply, moneytoadd )

	playermoney = moneytoadd  + ply:GetNetworkedInt("money")

	ply:SetNetworkedInt("money", playermoney )
	ply:SetPData("money", playermoney  )
 
end


function GM:PlayerInitialSpawn( ply )

	ply:SetNetworkedInt("money", ply:GetPData("money") )
 
end