• Problem with Table
    2 replies, posted
So currently I have a table with ULX groups in it, and the player's bar on the scoreboard will flash if they are in one of the usergroups in the table. (This works) I'm trying to get so that when a player is in a usergroup that is not in the table, it will stay one color. (40,40,40,255) I've looked over the Wiki to see if I can figure out a solution but its obvious the problem is right in front of me and i'm just not seeing it, I'd appreciate any help even if the issue doesn't get resolved. Don't shit post either, please. Error: attempt to index a nil value [B]Table[/B] [CODE]xScoreStaffRanks = { ["superadmin"] = { StaffColor = Color(0, 149, 255, 255) }, ["admin"] = { StaffColor = Color(0, 255, 0, 255) }, } [/CODE] [B] Code Snippet that is Affected[/B] [CODE] for k, v in ipairs(Players) do local bg = vgui.Create("DPanel", self.PanelList) bg:SetSize(self:GetWide()-10, 32) bg:SetPos(5,5) bg.Paint = function(w,h) local StaffColor = xScoreStaffRanks[v:GetUserGroup()].StaffColor local Flash = math.abs(math.sin(CurTime() * 2)) if xScoreStaffRanks[v:GetUserGroup()] == nil then surface.SetDrawColor(40,40,40,255) end surface.SetDrawColor(Color(StaffColor.r * Flash, StaffColor.g * Flash, StaffColor.b * Flash, StaffColor.a)) surface.DrawRect(0,0,bg:GetWide(),bg:GetTall()) end[/CODE]
Change the table to: [code]xScoreStaffRanks = { ["superadmin"] = Color(0, 149, 255, 255), ["admin"] = Color(0, 255, 0, 255) }[/code] Then do [code]local cStaff = xScoreStaffRanks[v:GetUserGroup()] if (cStaff == nil) then -- Do regular colours here else -- Do flashing colours here end[/code]
[QUOTE=code_gs;52645312]Change the table to: [code]xScoreStaffRanks = { ["superadmin"] = Color(0, 149, 255, 255), ["admin"] = Color(0, 255, 0, 255) }[/code] Then do [code]local cStaff = xScoreStaffRanks[v:GetUserGroup()] if (cStaff == nil) then -- Do regular colours here else -- Do flashing colours here end[/code][/QUOTE] How would I continue doing the flashing colors when I have the flashing colors set up like this?: [CODE] surface.SetDrawColor(Color(StaffColor.r * Flash, StaffColor.g * Flash, StaffColor.b * Flash, StaffColor.a))[/CODE] -EDIT- Nevermind, all works! Thanks for the help!
Sorry, you need to Log In to post a reply to this thread.