PlayerInitialSpawn hook not working?

Hi, I’m trying to make tags for a scoreboard, and when a player joins, an essential function called update_tags() is supposed to run, this function sets their tag to either what they set it to, or the default if they haven’t done so. At the moment when anyone joins their tag is NIL, until someone on the server changes their tag, which in that function calls update_tags.
When this happens everything gets set ok, but then when more people join they’re tag is nil.

So my question is, how do I call this function each time a player joins? This is my try …



hook.Add( "PlayerIntitialSpawn", "scoreboard_tag_spawn", function( ply )

	ply.sb_tag = ply:GetPData( "sb_tag",  "")
	update_tags()

end )


Thanks Facepunch!

what is the code for update_tags?



local function update_tags()

		local t = {}
		for k,v in ipairs( player.GetAll() ) do
			if v:GetPData("sb_tag") ~= nil and v.sb_tag == v:GetPData("sb_tag") then
				table.insert( t, v.sb_tag )
			else
				table.insert(t, firstToUpper(v:GetNWString("usergroup")))
			end

		end

		net.Start( "update_tags")
			net.WriteTable( t )
		net.Broadcast()

	end


ok well it LOOKS like you are trying to set the default “sb_tag” member to their usergroup (admin/superadmin/etc) if their tag is not set.

if that is the case you are doing it wrong. you should use v:GetUserGroup()

this isn’t about the update_tags function. that works because when it GETS called everything is right as rain. but it ISNT being called when someone new joins the server, THIS is the problem! D:

well it is… thats the thing.

your problem is in update_tags.

you are not defining the networked string “usergroup” anywhere unless you are setting it somewhere else its going to be nil.

GetPData uses the sqlite database that comes with garrysmod. a new user will not have any entries in your database so it will use your GetNWString(“usergroup”) which, like i said, if you are trying to set it to their usergroup, use v:GetUserGroup().

No… usergroup is a ulx networked string… I REITTERATE THAT WHEN UPDATE_TAGS IS CALLED, EVERYTHING WORKS FINE.



hook.Add( "PlayerInitialSpawn", "scoreboard_tag_spawn", function( ply )


You spelled Initial wrong, Also above, Stop being douche’s to people who help you, he misunderstood, you dont need to all caps yell at him.