Creating a gui via server

Im trying to open a character menu when a player joins, I decided that using net messages would be the easiest and best way to perform this, but it appears that the net message isnt working, I was wondering if anyone could shed some light on this

-I would like to say, in my init I call this function, with the ply parameter, and it all works, even my console prints the correct value, its just the net isnt working
Server Side:


util.AddNetworkString( "OpenCharacterMenu" )

local ply = FindMetaTable("Player")
GM.Character = (GM or GAMEMODE).Character or {}
function GM.Character:Initialize( ply )
	local hasCharacter = ply:GetNWBool("hascharacter")
	if hasCharacter != "true" then
		print(hasCharacter)
	elseif hasCharacter == "true" then
		print(hasCharacter .. "2")
		net.Start( "OpenCharacterMenu" )
		net.Send( ply )
	end
end

Client Side:


net.Receive( "OpenCharacterMenu", function( len )
	print("Test")
	vgui.Create("characterMenu")
end )

The reason I think the net message is messed up because console never prints test, but prints the hascharacter value…

Thanks in advance

:snip: See below

Why would I network the playeriinitialspawn when I could fix the current network message? Plus this function is called when on playerinitialspawn…

I also tried using InitPostEntity but I dont think thats gonna work in my case…

The player possibly doesn’t exist on the client yet, that’d be my guess

Edit: It works perfectly fine for me, so it SHOULD work if its called by PlayerInitialSpawn

[lua]
if SERVER then
util.AddNetworkString(“test1”)

hook.Add("PlayerInitialSpawn", "test1", function(ply)
	net.Start("test1")
		print("debug SENDING")
	net.Send(ply)
end)

else
net.Receive(“test1”, function(len)
print(“debug RECEIVING”)
end)
end
[/lua]

So ive done some more testing, it appears that the net is sending, but the file with net.receive isnt receiving

Serverside



util.AddNetworkString( "OpenCharacterMenu" )

function GM.Character:Initialize( ply )
	local hasCharacter = ply:GetNWBool("hascharacter")
	if hasCharacter != "true" then
		print(hasCharacter)
	elseif hasCharacter == "true" then
		print(hasCharacter .. "2")
		net.Start( "OpenCharacterMenu" )
			print("Sending Net")
			net.WriteBool( hasCharacter )
		net.Send( ply )
	end
end


Client-Side


net.Receive("OpenCharacterMenu",function( ply )
	
	hc = net.GetBool()
	if hc == "true" then
		vgui.Create("characterMenu")
	end
end)

Anyone else have some help?

You got a solution. IF you are using a gamemode that adds GM.Character:Initialize( ply ) then go check their docs. Else if you are using pure gmod default functions then use



hook.Add("PlayerInitialSpawn", "test1", function(ply)
		net.Start("test1")
			print("debug SENDING")
		net.Send(ply)
	end)


That is called once and only on the first time the player has connect to the server. If you add some other checks to see if they already have made a person then you dont send the message.

First of all, you read a networked bool with net.ReadBool(), not net.GetBool()

Secondly, it returns a boolean (true/false), not a boolean in string form (“true”/“false”)

[lua]
net.Receive(“OpenCharacterMenu”,function( len, _ )

hc = net.ReadBool
if hc then
	vgui.Create("characterMenu")
end

end)
[/lua]