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

The error:

gamemodes\rebelnpcwar\gamemode\init.lua:15: attempt to index global ‘Gm’ (a nil value)

The code:


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )

include( 'shared.lua' )


// Serverside only stuff goes here

/*---------------------------------------------------------
   Name: gamemode:PlayerLoadout( )
   Desc: Give the player the weapons I want to give
---------------------------------------------------------*/
--Sets settings for the player like Maximum Health, Gravity, etc
**function Gm:PlayerSpawn( ply )**
       self.BaseClass:PlayerSpawn( ply )
       ply:SetGravity( 1, true )
       ply:SetMaxHealth( 60, true )
       ply:Setwalkspeed( 325 )
               Ply:SetRunSpeed( 990 )
end

function GM:PlayerLoadout( ply )
       
       ply:StripWeapons()
       ply:Give( "weapon_crowbar" )
       ply:Give("weapon_gmod_tool" )
       ply:Give( "weapon_phygun" )
end

--What will happen when the player first spawns
function Gm:PlayerInitialSpawn( ply )
--Fixes errors for sandbox
self.BaseClass:PlayerInitialSpawn( ply )

--check if someone is an admin with an if statement
if ply:IsAdmin() then

-- To print a message(*where* *what*) atm it goes to the players chatbox
Ply:PrintMessage( HUD_PRINTTALK, "SERVER: Hey Zyler, welcome back! MUHUHAHAHAHAHA" )
end

end

--both a function (Gm.PlayerInitialSpawn) and an if statement (If ply:IsAdmin() then) need an end

Lua is case-sensitive.

Should be GM, not Gm.

Wow that was quick, thank you. It works now

Had the same problem, thank you…)

nice bump…

If this doesn’t work too, try calling “GAMEMODE” instead of “GM”.

Not when you’re loading entities, only inside hooks and timers you should use GAMEMODE.