for k, v in pairs(player.GetAll()) - Admins only.

Hello,

So I’m trying to create an admin Scoreboard, but when I try:


for k, v in pairs(player.GetAll()) do

         if v:IsUserGroup( "superadmin" ) then

                       -- scoreboard panel

         end

end

This does work, however it leaves gaps for people who aren’t that rank as well, meaning there are gaps inbetween peoples names who are superadmins.
What would be the best way to do this, getting rid of the gaps?

What scoreboard? More context needed

My own, trying to make my own, but I want admins to only show on it and not players.
By using the above code.

yea but that code alone would do nothing, provide more code or some explanation if you want us to be able to tell what’s wrong with it.

Make sure you’re not increasing the Y position of the each player panel when they’re not superadmin. That or you’re using the key in the loop as some sort of assistance for the Y position.

If I’m not making sense, could you post the code that draws their names?

Sure, this is the code for each panel.


for k, v in pairs(player.GetAll()) do
	if v:IsUserGroup( "superadmin" ) then
		ppp = vgui.Create( "DButton", bbgs )
		ppp:SetSize( bbgs:GetWide() - 5, 50 )
		ppp:SetPos( 5, 55 * (k-1) ) -- I think it'd to do with this bit, but not sure if it is.
		ppp:SetText( "" )
		ppp.Paint = function(self)
			draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 24, 109, 179 ) )
			draw.DrawText( v:Name(), "ButtonsFont", 5, self:GetTall() / 2 - 18, Color( 255, 255, 255 ), TEXT_ALIGN_LEFT )
	        end
        end
end

Yes it is exactly what causes this behaviour, the k is the key for v (player) in player.GetAll() table. You should setup your own variable and use it to calculate panel position.

Also, it’s not :GetUserGroup(...) but :IsUserGroup(...).

Create a table with all the ranks of staff ordered like so


local staff = {
admin = true,
superadmin = true
etc = true
}

then do the for loop and


if staff[v:GetUserGroup()] then
    --code
end


Try this:
[lua]
local y_pos = 0 – store y position outside of loop

for k, v in pairs(player.GetAll()) do
if v:IsUserGroup( “superadmin” ) then
ppp = vgui.Create( “DButton”, bbgs )
ppp:SetSize( bbgs:GetWide() - 5, 50 )
ppp:SetPos( 5, 55 * y_pos ) – use y value to get proper y position
ppp:SetText( “” )
ppp.Paint = function(self)
draw.RoundedBox( 0, 0, 0, self:GetWide(), self:GetTall(), Color( 24, 109, 179 ) )
draw.DrawText( v:Name(), “ButtonsFont”, 5, self:GetTall() / 2 - 18, Color( 255, 255, 255 ), TEXT_ALIGN_LEFT )
end

  y_pos = y_pos + 1 -- increase y value everytime we actually draw something

end
end[/lua]

Alternatively, you could use docking rather than setting the position. Which you would just call

Panel:Dock TOP on the button. (instead of SetPos)

[editline]24th October 2017[/editline]

Player:IsUserGroup is a function.

Awesome, that worked!
Thank you so much, helped a lot, been trying different ways for a while, will give the table ago as well to learn more.

Thanks guys!