[ERROR] gamemodes/darkrp/gamemode/modules/twrp/sv_gangs.lua:37: attempt to index a string value with bad key ('leader' is not part of the string library)

Hey all, I started programming in Garry’s Mod a good few years back, and I’ve never in the whole time that I’ve been programming in GLUA came across this kind of error, and it’s confusing the heck out of me.

Besides the point, if anyone could help me it would be appreciated.

Basically I’m making a gang system.



function meta:GetGang()
	if #Gangs > 0 then
		for k,v in pairs(Gangs) do
			if v.people then
				for _,sid in pairs(v.people) do
					if sid.leader and sid.leader == tostring(self:SteamID64()) then -- THIS IS LINE 37
						ply.CurrentGang = Gangs[k]
						return Gangs[k]
					end
				        if sid.viceleader and tostring(sid.viceleader) == tostring(self:SteamID64()) then
						ply.CurrentGang = Gangs[k]
						return Gangs[k]
					end
				for id,member in pairs(sid.members) do
					if tostring(member) == tostring(self:SteamID64()) then
						ply.CurrentGang = Gangs[k]
						return Gangs[k]
						end
					end
				end
			end
                                                return {}
		end
	end
end


My Table layout is like this when doing PrintTable(Gangs):

I’ve also tried using tostring on it, and also sid[“leader”] out of curiosity. But I really can’t get my head around this as it’s the first time I’ve came across this.

Hope someone can help, thanks all!

The error means you’re trying to treat a string as a table.
Do a print on sid and see what its value is.
You can then fix your table structure and/or code from there.

Its just sating leader doesnt exist in that table.
Can you put the table thing with proper “spacing”?
Its just to see how exactly the table is

[editline]27th October 2015[/editline]

Also what billy said

Spacing is proper, someone just didn’t set the tab-width properly in the code tag. He’s using tabs :smiley:

I mean in the table, not in the code

sid is a string value. you are indexing a string with another string (.leader and .viceleader), which will cause it to error like that.

Thanks so much all for the help, with the information you all gave me I’ve fixed the error, much appreciated guys!