[PS2] Printing PS2_Wallet.points on hud via cl_init.lua


		local Wallet = LocalPlayer().PS2_Wallet
                if Wallet == nil then timer.Simple( 60, function() end ) end
		local text = Wallet.points

Trying to get PS2 points to print to the HUD in jailbreak via the cl_init.lua I keep getting


[ERROR] gamemodes/jailbreak/gamemode/cl_init.lua:190: attempt to index local 'Wallet' (a nil value)
  1. fn - gamemodes/jailbreak/gamemode/cl_init.lua:190
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:109



when pointshop isn’t loaded this will appear. I tried to add the timer to make it wait if the wallet is nil but it doesn’t seem to work properly. Surely there must be a proper way to wait for the initialization of PS2 before drawing the hud

[lua]
if Wallet == nil then timer.Simple( 60, function() end ) end
local text = Wallet.points
[/lua]

Try to read this code in English. If your wallet doesn’t exist, you make a timer that… does nothing after 60 seconds. With that timer created, you define text as Wallet.points, but Wallet doesn’t exist, hence the error you get.

Creating a timer does NOT delay the execution of lines below. If you want to prevent the code from running before your Wallet doesn’t exist or whatever, add a return.

I figured it would halt execution until the timer stops. I tried to add a return like if wallet == nil then return end but then it returns out of the whole hud drawing and stops drawing the hud. Ideally I just need it to wait for pointshop 2 wallet to initialize somehow. It’s executing from inside this function


hook.Add("HUDPaint", "JB Notifications", function()
    if LocalPlayer and _DRAWHUD then
        

It draws fine but it spams the console like mad when joining the server

Just don’t draw the PS2 stuff until it loads with a if block:

[lua]
hook.Add(“HUDPaint”, “etc”, function()
// health armor w/e

if (Wallet) then
    // PS2 stuff
end

// ammo etc

end)
[/lua]

Thank you for showing me this. I really appreciate it.