Can't Get Hook to work!

This is my credit system script, but unfortunately, the Stats won’t load due to the hook not working, everything else works fine though. Please comment any help and any other problems with the script!




local STARTCREDITS = 5 -- This is the amount of credits that players start with
local ENABLE_SIMPLE_HUD = true -- Whether or not the simple HUD should be enabled - only draws credits
local PAYDAYS = true -- Whether or not paydays should occur, WARNING! KEEP AS TRUE
local PAYDAY_AMOUNT = 1 -- How much credits a person should be given every PAYDAY_INTERVALS, WARNING! CANT GO LOWER THAN 0.01
local PAYDAY_INTERVALS = 10 -- In seconds, how often should the player receive the PAYDAY_AMOUNT, WARNING MAKE SURE THIS HAPPENS ATLEAST EVERY 60 seconds!

if SERVER then 
	resource.AddFile( "resource/fonts/ram.ttf" )
	resource.AddFile( "resource/fonts/adult_swim.ttf" )
	
	-- Creates Credits
	local pm = FindMetaTable( "Player" )
	
	-- Saves and loads Credits
	function PlayerMoneyDSpawn( ply )
		ply:StatsLoad()
	end
	hook.Add("PlayerInitialSpawn", "LoadStats", LoadStats)

	function SaveStats( ply )
		ply:StatsSave()
	end
	hook.Add("PlayerDisconnected", "SaveStats", SaveStats)

	function pm:StatsSave()
		self:SetPData( "Credits", self:GetNWInt( "Credits" ) )
	end

	function pm:StatsLoad()
		if self:GetPData( "Credits" ) == nil then 
			self:SetPData( "Credits", STARTMoneyD ) 
		end
	end
	
	-- Custom functions
	function pm:AddCredits( cdn ) -- Adds credits to a player's current amount, Use: pm:AddCredits( amount ).
		if cdn > 0 then
			local current = tonumber(self:GetPData( "Credits" ))
			self:SetCredits( current + cdn ) 
		end
	end
	
	function pm:SetCredits( cdn ) -- Sets a players credits, Use: pm:SetCredits( amount ).
		self:SetPData( "Credits", tonumber(cdn) )
		self:SetNWInt( "Credits", tonumber(cdn) )
	end
	
	function pm:GetCredits() 
		local current = tonumber(self:GetPData( "Credits" ))
		return current
	end
	
	-- Paydays
	if( PAYDAYS == true ) then
		function StartPaydays( ply )
			timer.Create( "Payday_" .. ply:UserID(), PAYDAY_INTERVALS, 0, function() -- Starts a unique timer for the player.
				ply:AddCredits( PAYDAY_AMOUNT )
			end)
			timer.Start( "Payday_" .. ply:UserID() )
		end
		hook.Add("PlayerInitialSpawn", "StartPaydays", StartPaydays)
		
		function StopPaydays( ply ) 
			if( timer.Exists( "Payday_" .. ply:UserID() ) ) then -- Checks to see if the timer exists, stops errors.
				timer.Remove( "Payday_" .. ply:UserID() ) -- Makes sure that the timer is removed on the players disconnect, decreases lag.
			end
		end
		hook.Add("PlayerDisconnected", "StopPaydays", StopPaydays)
	end
	
end 
	
if CLIENT then -- Draws HUD

	surface.CreateFont( "adultswim_20", {
	font = "Helvetica Neue",
	size = 20,
	weight = 100,
	antialias = true,
	additive = true,
	bold = true,
	})

	
	if( ENABLE_SIMPLE_HUD == true ) then
		local function Dmatter_Draw()
			 
			draw.RoundedBox( 0, 2.5, 2.5, 100, 25, Color(99, 99, 99, 150))
			
			local playersCD = string.Comma(math.Round(LocalPlayer():GetNWInt( "Credits" )))
			draw.DrawText(playersCD .. " Credits", "adultswim_20", 15, 5, Color(255,255,255,255))
			
		end
		hook.Add("HUDPaint", "DmatterPainting", Dmatter_Draw)
	end
	
end




Did you try adding prints to know where does your code exactly stop working as intented?

Edit: I think I found the error


hook.Add("PlayerInitialSpawn", "LoadStats", LoadStats)

Here LoadStats is not declared, wouldn’t that throw an error?

Fixed it thank you! That was an error, but it wasn’t the main one.
I just needed to put this in the LoadStats function




		local current = tonumber(self:GetPData( "Credits" ))
		self:SetCredits( current )