Dark RP like money help!

Well I have been trying to make Dark RP money for my server… (I am remaking Dark RP , its going well) but for some god damn reason I can’t make a custom money system because when server starts up:

[HUD] Loads
[Scoreboard] Loads
[Custom Chatbox] Dosen’t load unless you reload files whilst the player is ingame!
[NWInt/PData for money] Same error as aboth!
[Jobs] Load but NWInt is erroring

Post some code.



data = {
    -- Get Current Data
    getMoney = ply:GetNWInt( "coins" )
	getLocation = ply:GetNWString( "location" ) 
	
	-- Set Current Data
	setMoney = ply:SetNWInt()
	
	-- Get Saved Data
	getMoneyData = ply:GetPData( "saved_coins" )
} 

function GM:PlayerInitialSpawn( ply )

if ply then
   
   if data.getMoney == nil then
      data.setMoney( "coins", 100 )
	  else
	  data.setMoney( "coins", data.getMoneyData )
   end 
   
end   
   
   
end


Shouldn’t it be something like



local data = { -- data is a pretty generic global variable so I made it local just in case

    -- Get Current Data
	getMoney = function( ply ) return ply:GetNWInt( "coins" ) end,
	getLocation = function( ply ) return ply:GetNWString( "location" ) end,
	
	-- Set Current Data
	setMoney = function( ply, number ) ply:SetNWInt( "coins", number ) end,
	
	-- Get Saved Data
	getMoneyData = function( ply ) return ply:GetPData( "saved_coins" ) end,

}

function GM:PlayerInitialSpawn( ply )

	if data.getMoney( ply ) == nil then
		data.setMoney( ply, 100 )
	else
		data.setMoney( ply, data.getMoneyData( ply ) )
	end  
   
end


[editline]15th August 2016[/editline]

Also, this:



if data.getMoney( ply ) == nil then
	data.setMoney( ply, 100 )
else
	data.setMoney( ply, data.getMoneyData( ply ) )
end  


Could be condensed into this:



data.setMoney( ply, data.getMoney( ply ) and data.getMoneyData( ply ) or 100 )


True, but still. It’s not this that is causing the error. Ever since I have tried using PData and NWInt it keeps failing! Over and Over again… like I can’t load all the files unless I go into the file and click save on all of them… and then it will load in game? What is this? AND my timers, don’t even load into game from PlayerInitialSpawn maybe it’s not being called with Client or something?

Do you ever actually SET the player’s Pdata?

[editline]15th August 2016[/editline]

Also, I compressed your script a bit more:



local ply = FindMetaTable( "Player" )

-- Get data
function ply:GetMoney() return self:GetNWInt( "coins" ) end
function ply:GetLocation() return self:GetNWString( "location" ) end
-- Set data
function ply:SetMoney( number ) self:SetNWInt( "coins", number ) end
-- Get saved data
function ply:GetMoneyData() return tonumber( self:GetPData( "saved_coins", 100 ) ) end

function GM:PlayerInitialSpawn( ply )
	ply:SetMoney( ply:GetMoneyData() )
end


^ Untested

Wait a second, it’s not that! Thats not working, WHEN I joined the SERVER, it said 0 coins… I refreshed and EVERY gamemode .lua file I have worked? how on earth do you refresh ingame? aka when player joins it auto refreshes?

[editline]15th August 2016[/editline]

Oh and, after changing PData or NWInt it just reverses its self like wtf… am I better of just getting someone to make a money system?

I think I might know the problem - it says here:

Player:GetPData returns a STRING, not a number. Therefore, the problem could be that SetNWInt isn’t working because you’re trying to set a STRING rather than a number

True, but I mean… it WORKS perfectly after I refresh the file whilst ingame.
Is there a way I can LOAD all the lua files on the Client, as soon as they join? Like run it all?

Sorry, but can you please post the file path that you put this file in? Sometimes if the file path can make it only work once you refresh it

garrysmod\gamemodes\gmtest\gamemode\init.lua

But my Gamemode, has really run much but the PlayerSpawn, HUD (hudpaint runs forever), Scoreboard… everything else needs a refresh?

Maybe I need to Reload all my files?