Gamemode Function Receiving nil value.

So basically I have a problem with a custom GM:Function receiving a nil value when I know for sure it isn’t receiving one.

This is basically what is is:


Test = {}
Test.Test = “Hiya”

GM:ReceiveTest(Test) //So it receives all the information at startup.

That file is shared by clientside AND server side… (did addcsluafileetc…).

However in my shared.lua I have a GM:Function.

Receiver = {}
function GM:ReceiveTest(Test)
Receiver = Test

And the error is of course it is receiving a nil value. Any thoughts? Comments?

What is the nil value exactly?


I mean, what variable?

To use a gamemode function after the gamemode has been registered, you have to use GAMEMODE and not GM, so

GAMEMODE:ReceiveTest( TEST )

Is the correct syntax.

It is used on startup though… As in when the gamemode initializes I want it to run the function, mianly because i will have multiple files like test that will be used with it.

error: (On startup) /test.lua:12 attempt to call method ‘ReceiveTest’(a nil value)

It is registered before it is initialized. Besides why don’t you just make it a regular function? It’ll work just as well.

Meh, I thought it would just be easier to have it, that way it would execute on both client and server when either of them intialized, reducing the amount of coding I would have to do.

Oh, i forgot to mention that my receiver table is actually:

[LUA] GM.Receiver = {} [/LUA]

and @Entoros I changed it to gamemode.Call(“ReceiveTest”, Test) and this is the error it gave me.

 Attempt to index global value 'GM' a nil value. 

which doesn’t make sense considering GM is a table that is instantiated by default for servers.

Oh but that is also when I run a function trying to print out that sucker to debug.

THIRD Edit: yeah I forgot doesn’t do it at the start >.>


Okay so I re-worked it a little because none of you liked my usage of the GM table, and now it just seemed to not run the AddItem for some reason… Here it is:

local Test = {};
Test.Name = “Testy”;
Test.Test = “Hiya”;

hook.Add(“Initialize”, Test.Name, ReceiveTest, Test)

no errors, however I’m not 100% sure its calling it, in fact im almost positive it isn’t because of this function

Receiver = {}
function ReceiveTest(Test) Receiver[Test.Name] = Test end

function minitest(ply, cmd, args)
concommand.Add(“mini”, minitest)

for some reason it keeps sayign that Receiver[“Testy”] was attempted to be indexed but came back as a nil value.

GM is in fact removed. GAMEMODE is the table you want.

Here’s a useful read :

Yeah I Figured using GM would be a bad idea and I tried using GAMEMODE, however it said that it attempted to index gamemode as a nil value :confused:

if you look towards the end of my last post you will see what I ended up doing and the error I am still getting.

I can’t put a finger on what is wrong but also for some reason now when I move a table say TeamInfo from Init.lua into shared.lua it always says attempt to index global TeamInfo a nil value… etc.

maybe I have included my shared.lua wrong? Because I know I should be able to move that table into shared… because on the serverside I use it alot but none in the clientside, however it should be possible to instantiate all the stuff in that table via shared am I right? This is all so confuzzling.

I fixed the teaminfo thing, that was a silly error.


***I figured it out guys thanks! The problem was that i wasn’t including the test.lua file AFTER those GM:ReceiveTest functions… so it was screwing up somehow.

it works <3 :)***