Client event on InitSpawn

Hi,

I’m trying to display a panel when a player has finished his InitSpawn, but nothing happened.

The Code ( placed in autorun/ ) :


function PANELHPST()
	print("DEBUG")
	if CLIENT then
		local harrypotterpanel = vgui.Create("DFrame")
		harrypotterpanel:SetSize(740,360)
		harrypotterpanel:SetTitle("")
		harrypotterpanel:ShowCloseButton(false)
		harrypotterpanel:SetDraggable(false)
		harrypotterpanel:Refresh(true)
		harrypotterpanel:Center()
		harrypotterpanel:MakePopup()
		harrypotterpanel.Paint = function()
			draw.RoundedBox(0,0,0,740,360,Color(200,200,200, 255))
		end

		for k,v in pairs(team) do
			local x = v.id * 187 - 185
			local button = vgui.Create("DButton",harrypotterpanel)
			button:SetSize(172,352)
			button:SetPos(x, 5)
			button:SetText("")
			button.Paint = function( s, w, h )
				local mat = Material(v.image,"smooth mips")
				surface.SetDrawColor( 255, 255, 255, 255 )
				surface.SetMaterial( mat )
				surface.DrawTexturedRect( 0, 0, w, h)
			end
			button.DoClick = function()
				RunCmd("/"..v.job)
				harrypotterpanel:Remove()
			end
		end
	end
end

if SERVER then
	hook.Add( "PlayerInitialSpawn", "HPST", PANELHPST )
end

So here, the “print(“DEBUG”)” works but in the “if CLIENT then … end” nothing appear.

Just use net messages.


function PANELHPST()
	local harrypotterpanel = vgui.Create("DFrame")
	harrypotterpanel:SetSize(740,360)
	harrypotterpanel:SetTitle("")
	harrypotterpanel:ShowCloseButton(false)
	harrypotterpanel:SetDraggable(false)
	harrypotterpanel:Refresh(true)
	harrypotterpanel:Center()
	harrypotterpanel:MakePopup()
	harrypotterpanel.Paint = function()
		draw.RoundedBox(0,0,0,740,360,Color(200,200,200, 255))
	end

	for k,v in pairs(team) do
		local x = v.id * 187 - 185
		local button = vgui.Create("DButton",harrypotterpanel)
		button:SetSize(172,352)
		button:SetPos(x, 5)
		button:SetText("")
		button.Paint = function( s, w, h )
			local mat = Material(v.image,"smooth mips")
			surface.SetDrawColor( 255, 255, 255, 255 )
			surface.SetMaterial( mat )
			surface.DrawTexturedRect( 0, 0, w, h)
		end
		button.DoClick = function()
			RunCmd("/"..v.job)
			harrypotterpanel:Remove()
		end
	end
end


net.Receive("HPST", PANELHPST)

if SERVER then
	util.AddNetworkString("HPST")
	hook.Add( "PlayerInitialSpawn", "HPST", function()
		net.Start("HPST")
	end)
end

?