attempt to index a string value with bad key

I’m fresh stepping forward into lua but I love problem solving and so I tend to look into scripts and have a go at fixing.
I feel like it’s the best way to learn lua (personally) but here I’ll go ahead and post the problem.(This is not my own script and hold no ownership but has been released publicly claiming we could do whatever)

[DarkRP] gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:742: attempt to index a string value with bad key (‘Citizen’ is not part of the string library)

  1. error - [C]:-1
  2. __index - lua/includes/extensions/string.lua:297
    3. GenerateJobLabels - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:742
    4. GenerateJobsTab - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:658
    5. Init - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:30
    6. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:37
    7. Call - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:802
    8. unknown - gamemodes/darkrp/gamemode/modules/base/cl_gamemode_functions.lua:46

the file > https://github.com/SurelyExploding/noobonicplague/blob/bb851fbc429f82d10e6dd96c18595ac336e67592/gamemode/modules/noobvgui/cl_customf4menu.lua

tl:dr basically where the problem is (or so I think)


	if ( customLimitTable[ team.GetName( ( tonumber( index ) or 0 ) ) ] ) then
		jobLimit = customLimitTable[ team.GetName( index ) ]
	end

I have tried to fix it but I’m hopeless, just curious as to how to fix the problem
I know the code is trying to index a string value but then what do we put inbetween


( tonumber( index )

sorry if I come off as retarded

I think the problem is that customLimitTable is a string. It’s meant to be a table. It’s set here:



local customLimitTable = SHNOOB_VARS:Get( "CustomJobLimits" )


Maybe try printing customLimitTable to see if there’s a way to convert it to an actual table, or if it is actually a string?

[editline]31st October 2017[/editline]

I’m just guessing based on the code and the error. I think at some point the code is doing what could be simplified to this:



local customLimitTable = "blah blah this is not a table"
if ( customLimitTable[ "Citizen" ] ) then -- this would probably give a similar error


In this code you can see why an error would occur.

I’m going to be honest and say I’m not exactly sure how to print a string and see the output when working with a server, do i catch it on the console?

do i just print table instead?

I have no clue if this will work, but try adding this to line 741:



local customLimitTable = SHNOOB_VARS:Get( "CustomJobLimits" )
print( customLimitTable, type( customLimitTable ) )


It should just print in the client console since it’s a clientside file.

If you don’t know what I’m talking about then if you go into the options and click advanced then there should be a developer console checkbox that you can toggle with ` or ~ or something like that.

It might be hard to find it in the console log though. If it is, try doing this:



print( "INSERT SOMETHING HERE", customLimitTable, type( customLimitTable ) )


hopefully you’ll see it eventually, probably just before the error

Did what you said and this is what came up, you were right i think

INSERT SOMETHING HERE nil string

[DarkRP] gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:743: attempt to index a string value with bad key (‘Citizen’ is not part of the string library)

  1. error - [C]:-1
  2. __index - lua/includes/extensions/string.lua:297
    3. GenerateJobLabels - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:743
    4. GenerateJobsTab - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:658
    5. Init - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:30
    6. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:37
    7. Call - gamemodes/darkrp/gamemode/modules/noobvgui/cl_customf4menu.lua:803
    8. unknown - gamemodes/darkrp/gamemode/modules/base/cl_gamemode_functions.lua:46

[editline]31st October 2017[/editline]

You’re a god, thank you.