A nil value problem

Why won’t this work ive tryed a few things but i can’t get it to work.
This is an entities but shouldn’t it work when i have the ‘item’ as a
value in my gamemode? how do i fix this?.


attempt to index global 'item' (a nil value)

[lua]function PANEL:Agree()

if ( item.uniqueID == "milktest" ) then
    if (player:GetCount("milktest") == 1) then
       constraint.RemoveAll( trace.Entity )
	   timer.Simple( 0, RemoveEntity, trace.Entity )
	   gm.inventory.update(player, item, -1)
	   gm.player.giveMoney(player, trace.Entity:GetNWEntity("prizesell"))
       gm.player.notify(player, "You don't have a milktest",1)		


Show us where you’re having the item value set, because I doubt it’s either local or not being set at all.

I have allot of items in my items folder so it is set, and it doesn’t matter if i set “local ITEM = {};” in
the client ore server side file its still the same, and btw that code is in client should i add something else in
the server side/shared ?.

You don’t define item in your client code.

Ive tryed adding local ITEM = {}; to the client code but doesn’t work.
Isn’t that just what i have to do? but should i put it in the top of the file ore above that function?.

You are grabbing the variable ‘item’ out of thin air, you have to retrieve it somehow (gm.item.get()?)
Variables don’t just pop up conviniently when you need them.

Okay yes i understand that i can’t get something that isnt there. But i don’t really
understand what you mean with that item.get?

EDIT: I tryed item = gm.item and it doesn’t give an error now but the code doesn’t do anything. so is it the code there is something wrong with ore
doesn’t that item = gm.item work.

Look over your logic.
gm.item is a table containing all functions related to item handling item creation etc as well as a table of all the stored items, is this what you want to use in your function? No, I think you want one specific item in the players inventory.

Did you write the item library?

The code i send above is from libraries/sh.item.lua.
Im trying to make so when you press Okay on a button the npc takes 1 milktest from you inventory
if you have one and you get 800 money for it.

Well first of all the inventory is server-side, so when you press ok you need to run a console command (the only way to do client->server communication)
Then server-side you create that concommand
concommand.Add(“something_milkshop”,function(ply) --ply is the player who ran the command
if gm.item.destroy(ply,“milktest”) then --gm.item.destroy return true if the player has the item
ply:GiveMoney(800) --I dunno how you handle your money but something like this
You’ll want to do some more checks like making sure the player is in range of the npc.

If i do that RunConsoleCommand doesn’t i buy the item then? i want to take it from my inventory

EDIT: Can’t i just put it in a server side file or is derma a clint side only?.

Derma is client only, RunConsoleCommand will run it from the one using the menu (you)

Okay client side is so not my favorit. Everything is a nil value also the code you send GiveMoney,giveMoney,item,ITEM,destroy,Destroy everything ive tryed is a nil value.
Can’t i make the code in a server side and just connect them to the client side?.

That’s what I told you to do, you put RunConsoleCommand client-side and concommand.Add server-side.

Oh Okay! now i get it thank you very much for helping me!.
i was putting RunConsoleCommand in client and concommand in client :rolleyes: