attempt to call method 'Money_Get' ( a nil value). Problem only happens on other people except host

I’ve been having a problem that’s most likely related to clientside / serverside stuff. I want to add a shop where players can use it, and buy items, and get on with their business. I’ve written the code for the shop, but it only works on myself when i’m hosting on a listen server. Anybody else in the same server gets this error message “attempt to call method ‘Money_Get’ ( a nil value)”, at line 12 of shared.lua, when they try to make a purchase.


[lua]ENT.Base = “base_ai” – This entity is based on “base_ai”
ENT.Type = “ai” – What type of entity is it, in this case, it’s an AI.
ENT.AutomaticFrameAdvance = true – This entity will animate itself.

function ENT:SetAutomaticFrameAdvance( bUsingAnim ) – This is called by the game to tell the entity if it should animate itself.
self.AutomaticFrameAdvance = bUsingAnim

function GivePlayerAWeapon( ply, cmd, args ) --Starting our function, ply is the player who ran the console command, cmd is the command name (in this case “weapon_give”), args is the arguments of the console command
if args[1] == “pistol” then --if the 1st argument is “pistol” then do:
if ply:Money_Get() >= 500 then
ply:Give(“weapon_pistol”) --give the player a pistol
ply:Money_Take( 500 )
ply:ChatPrint(“You got a pistol!”) --print “You got a pistol!” in the chat

		ply:ChatPrint("Not enough dosh for that one!")
end --close our if loop
if args[1] == "smg" then --if the 1st argument is "smg" then do:
	ply:Give("weapon_smg1") --give the player an SMG
	ply:ChatPrint("You got an SMG!") --print "You got an SMG!" in the chat
    end--close our if loop

end --close our function

concommand.Add(“weapon_take”, GivePlayerAWeapon) --make the console command “weapon_take” run the GivePlayerAWeapon function

– Since this file is ran by both the client and the server, both will share this information.[/lua]

[lua]////////// You may use/edit this script for ANYTHING! //////////
////////// ITS LICENCE FREE //////////
////////// //////////

local STARTMONEY = 1000 – This is the amount of cash that players start with
local PAYDAYS = true – Should there be paydays? true = yes, false = no
local PAYDAY_AMOUNT = 1 – If there are paydays, what should the salary be?
local PAYDAY_INTERVAL = 1 – If there are paydays, what should the payday interval be? (Seconds)
local PAYDAY_SOUND = true – If there are paydays, should a sound play when there’s a payday? true = yes, false = no
local MONEY_HUD = true – Should the money be displayed on the screen? true = yes, false = no

if SERVER then – If this file is on a server do: (SERVER)
local pm = FindMetaTable(“Player”) – We state that entities under the meta table “player” is called pm, just to make it easier!

function PlayerMoneySpawn( ply )
hook.Add("PlayerInitialSpawn", "MoneySystemStart", PlayerMoneySpawn)

function pm:Money_Create() -- DONT TOUCH! THIS FUNCTION SAVES THE SHIT
	print("Creating money account for: "..self:Nick())
	if self:GetPData( "cash" ) == nil then -- if there is no data under "cash", create some!
	self:SetPData( "cash", STARTMONEY ) -- if there is no "cash" data, give them 15 cash to begin with!


function pm:Money_Set( cash ) -- player:Money_Set = SET THE MONEY OF A PLAYER
	self:SetPData( "cash", tonumber(cash) ) -- Saves the cash to the server
	self:SetNWInt( "cash", tonumber(cash) ) -- Sends the amount to the players' screens

function pm:Money_Add( cash ) -- player:Money_Add = ADD MONEY FOR A PLAYER
	if cash > 0 then -- If the cash to give is over 0...
		local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
		self:Money_Set( current + cash ) -- Set the money to: The old amount of money + the money wished to be added

function pm:Money_Has( cash ) -- player:Money_Add = GET THE MONEY FOR A PLAYER
	local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
	if current >= tonumber(cash) then -- if the old amount si over the amount checked...
		return true -- say it's true!
		return false -- if not, say it's false!

function pm:Money_Get() -- player:Money_Add = GET THE MONEY FOR A PLAYER
	local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
	return current

function pm:Money_Take( cash )  -- player:Money_Add = TAKE MONEY FOR A PLAYER
	if self:Money_Has( cash ) then -- if you got the amount of money...
		local current = tonumber(self:GetPData( "cash" )) -- Get the old amount of money
		self:Money_Set( current - cash ) -- Take the old amount of money and take away the amount given!

if PAYDAYS then
	timer.Create( "payday_timer", PAYDAY_INTERVAL, 0, function()
		for k, ply in pairs(player.GetAll()) do
			ply:Money_Add( PAYDAY_AMOUNT )
			--if PAYDAY_SOUND then
			--	ply:EmitSound("items/ammo_pickup.wav")
	end	)


local function Money_Draw()
	///////// FOR ADVANCED USERS: MAKE A HUD HERE ///////////////
	if not MONEY_HUD then return end
	local mulleh = LocalPlayer():GetNWInt( "cash" ) -- The amount of money you got
	draw.DrawText("Dosh: "..mulleh, "Trebuchet18", 60, 60, Color(255,255,255,255))
hook.Add("HUDPaint", "MoneyPainting", Money_Draw)


Did you include and AddCSLua the file properly?

Not sure if needed, but I tried including and using the AddCSLua on the moneysystem.lua and it failed to include. Error message is “Couldn’t include file ‘moneysystem.lua’ (file not found)”. My folder hierarchy has moneysystem.lua in the gamemode folder, and the npc_shop lua files in the entities folder.

Money_Get() is a server-side only function, your calling it via a shared console command. Make Money_Get() a shared function, or try making that concommand server-only.

That worked, thanks!