Why isn't this Hook working? referencing and changing variables across client lua files...

Right now there is a custom scoreboard that displays an image.

Objective: CHANGE that image by clicking on a derma button. important this is in another client file, not the cl_init

Currently I am able to get the image to display and the derma button prints to console but it never does anything to the image. It doesn’t change it at all. No errors given.


 GM.scoreimage = GAMEMODE and GAMEMODE.scoreimage or {}
local scoreimage = GM.scoreimage
	

function scoreimage:show()
	local frame = vgui.Create("DFrame")
	
	frame:SetPos( 100, 100 )
	frame:SetSize( 1680,950 )
	frame:Center()
	frame:SetTitle("Quick Reference")
																	-- Add image to Frame
		local myimage = vgui.Create("DImage")
		self.myimage = myimage
		myimage:SetPos( 200, 400 )	-- Move it into frame

		myimage:SetSize( 1200, 450 )	-- Size it to 150x150
		myimage:SetImage("image1.png")
	
	function scoreimage:hide()
		frame:SetVisible(false)
		myimage:SetVisible(false)
	end
end




hook.Add("ScoreboardShow", "quickref", function()
	scoreimage:show()


end)

hook.Add("ScoreboardHide", "quickref2", function()
	scoreimage:hide()
	
end)

function GM:ScoreboardShow()
end

function GM:ScoreboardHide()
end












//////// from function of derma button in another client lua file 

	
				Button42 = vgui.Create( "DButton", MED )
				Button42:SetSize(200, 100)
				Button42:SetPos(1340,610,3)
				Button42:SetText( "Scoreboard Update Test" )
				Button42.DoClick = function ()
				
				GAMEMODE.scoreimage.myimage:SetImage("image2.png") 
				GAMEMODE.scoreimage.myimage:SetSize( 1600, 800 )

				print (GAMEMODE.scoreimage.myimage)
				
			
				end

Is my syntax wrong because the DoClick function isn’t working. I get NO errors but the image isn’t update. The size isn’t changing either so I know it’s not a materials/folder issue. I’m trying to change a variable found in different cl_init file but I was told you could do that if GAMEMODE is used probably. Must be a syntax issue.

  1. Is this even for a gamemode? If not, don’t use GM and GAMEMODE.
  2. You’re overwriting the hook by overwriting the main function.

Yes it is for a game mode.

2- I should lose the last two lines?

Try making a separate function for the scoreimage named, like, ‘Rebuild’ or ‘Recalculate’, (whatever you want, honestly), and then inside it, remove the image portion of the button and recreate it with the new image path

roughly this


function scoreimage:SetImg(path)
	if IsValid(self.myimage) then
		self.myimage:Remove()
	end

	self.myimage = vgui.Create("DImage", self)
	self.myimage:SetPos( 200, 400 )
	self.myimage:SetSize( 1200, 450 )
	self.myimage:SetImage(path)
end