Help with MetaTables Errors

The following code seems to break very easily and I cannot determine why. It works for some instances but for the majority of the time just breaks the gamemode. Please help!

cl_init.lua showing errors from:

[ERROR] gamemodes/combinesandrebels/gamemode/cl_init.lua:17: attempt to call method 'GetXP' (a nil value)
  1. v - gamemodes/combinesandrebels/gamemode/cl_init.lua:17
   2. unknown - lua/includes/modules/hook.lua:84

cl_init.lua :

function XPDrawHud()
	draw.WordBox( 25, 50, 150,"Experience: " .. tostring(LocalPlayer():GetXP()),"Default",Color(50,50,75,100),Color(255,255,255,255))

hook.Add("HUDPaint", "HUD_TEST2", XPDrawHud)


XP_STARTAMOUNT = 0 --Can be changed to your starting amount
function FirstSpawnxp( ply )
	local exp = ply:GetPData("XP") --Get the saved XP amount
	if exp == nil then --If it doesn't exist supply the player with the starting XP amount
		ply:SetPData("XP", XP_STARTAMOUNT) --Save it
		ply:SetXP( XP_STARTAMOUNT ) --Set it to the networked ints that can be called from the client too
	ply:SetXP( exp ) --If not, set the networked ints to what we last saved
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawnxp )


function meta:AddXP(amount)
	local current_exp = self:GetXP()
	self:SetXP( current_exp + amount )
function meta:SetXP(amount)
	self:SetNetworkedInt( "XP", amount )
function meta:SaveXP()
	local exp = self:GetXP()
	self:SetPData("XP", exp)
function meta:SaveXPTXT()
	file.Write(gmod.GetGamemode().Name .."/XP/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetXPString())
function meta:TakeXP(amount)
   --Add XP function here
function meta:GetXP()
	return self:GetNetworkedInt( "XP" )

It was working for a short period of time…I believe it has something to do with file.write?

Someone with greater knowledge than myself please help!

[editline]13th May 2014[/editline]

Upon commenting out the error above, I get the following:

Couldn't include file 'shared.lua' (File not found) (@gamemodes/combinesandrebels/gamemode/cl_init.lua (line 1))
Couldn't include file 'sh_player.lua' (File not found) (@gamemodes/combinesandrebels/gamemode/cl_init.lua (line 2))
Couldn't include file 'sh_meta.lua' (File not found) (@gamemodes/combinesandrebels/gamemode/cl_init.lua (line 3))

How is this possible? I assure you that the files are there…

I’m assuming on sh_player.lua you have this:-

local meta = FindMetaTable(“Player”)

Yes I do on both sh_player.lua and sh_meta.lua but the line for that in sh_meta.lua is:

local metatab = FindMetaTable("Player")

-The two shouldn’t conflict anyway though.

I just do not see the issues here. I am starting to think there is something keeping the files from being included.

[editline]13th May 2014[/editline]

What would keep files from being included?

Another way of going around this would be to network a table of your XP data to the actual client. Other than that check you are including the shared files on both the client and the server, remember you need to AddCSLuaFile your shared file!

All of the files are included in both the init.lua and cl_init.lua

All of the files are also AddCSLuaFile() 'd in the init.lua …

Even being so, I have all of the files on my clientside version of the gamemode as well which is identical to the server’s version.

Why would the files not be included?

Upon running my init.lua file through a Lua file tester I found that errors were not presented to console as they should have been. Because the init.lua was broken, it seems that many files were not included serverside. It was something as stupid as me not including function arguments -_-…

Thanks for your help!