• "attempt to index global 'chat' (a nil value)"
    5 replies, posted
I want to use [URL="http://wiki.garrysmod.com/page/chat/AddText"]chat.AddText[/URL] for some things in an script i'm writing, however for some reason no matter what I it just shows me this error: [CODE][ERROR] lua/pointshop/items/sniper/weapon_zm_rifle_ps.lua:5: attempt to index global 'chat' (a nil value) 1. OnBuy - lua/pointshop/items/sniper/weapon_zm_rifle_ps.lua:5 2. PS_BuyItem - lua/pointshop/sv_player_extension.lua:254 3. func - lua/pointshop/sv_init.lua:13 4. unknown - lua/includes/extensions/net.lua:32 [/CODE] From this code: [CODE]function ITEM:OnBuy(ply) chat.AddText( Color( 100, 100, 255 ), ply, ", how are you doing?" ) ply:Give(self.WeaponClass) end[/CODE] and/or [CODE]concommand.Add( "chattext", function(ply) chat.AddText( Color( 100, 100, 255 ), ply, ", how are you doing?" ) end )[/CODE] Yes, I've tried [CODE]if CLIENT then[/CODE] It doesn't do anything then. I'm really irritated, because I've used chat.AddText before and it worked. What's wrong now? --Santifocus
Try [code]if CLIENT then[/code] again. [code]function ITEM:OnBuy(ply) if (CLIENT) then chat.AddText( Color( 100, 100, 255 ), ply, ", how are you doing?" ) else ply:Give(self.WeaponClass) end end[/code] [editline]13th November 2017[/editline] are pointshop items even shared?
Dunno if they are but doing your code gives you the weapon so I guess they are not. What about the concommand.Add? Because it doesn't work either
[QUOTE=Santifocus;52885356]Dunno if they are but doing your code gives you the weapon so I guess they are not. What about the concommand.Add? Because it doesn't work either[/QUOTE] You are running the code in the server realm (indicated by call stack starting from a serverside file). The Chat library is only available clientside, and calling it serverside will produce an error. A console command added in the server realm will only be called on the server, therefore the same error would also be produced from calling a serverside command that requires a clientside library. I don't know much about pointshop, or whether it allows items to define clientside code, but if not, or if you are in a rush, simply network it using the Net library, and call your chat library functions clientside. [editline]13th November 2017[/editline] Ninja'd :(
Tyvm! Matt helped me out twice now ^^
Sorry, you need to Log In to post a reply to this thread.