Help me with this problem? (related to tables)

-snip- fixed

Maybe you could use console command arguments-



function BuyWeap( ply,command,index )



Get rid of the loop, instead use the first argument of index. (In a console command, the 3rd argument is a table of arguments. Ignore command, but keep it in there)



        local Weap=Weapon[ tonumber(index[1]) ]
        if ply:GetNWInt( "Money") < Weap.COST then
            ply:ChatPrint("You don't have enough money!")
        else
            ply:Give(tostring(Weap.NAME))
            ply:AddMoney(-Weap.COST)
        end


Then in the DoClick function, pass the object’s index to the console command-



icon.DoClick=function( icon )
      RunConsoleCommand("BuyWeap",k.."")
end


I concatenated k with an empty string because console command arguments are supposed to be in string format… It might work without it, but I’d advise staying with string in case it becomes case sensitive.

Hopefully that works! ^^’ It seems like it should, but GMod’s lua doesn’t always work as it should or as you would expect it…

thanks, it’s fixed now :smiley: