Scoreboard isn't loading correctly

Ok, so when i’m joining my server, scoreboard won’t start correctly, i need to edit the file to make it working.

The line with error is:


[ERROR] addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/sh_hudreplacement.lua:260: attempt to index global 'GM' (a nil value)
  1. unknown - addons/darkrpmodification-master/lua/darkrp_modules/hudreplacement/sh_hudreplacement.lua:260

and the line 260 is:
(It starts only when i edit the file and i’m on server)


function GM:ScoreboardShow()

but when i make it:


function GAMEMODE:ScoreboardShow()

It starts correctly when i join, but when i edit the file it disappears to the normal sandbox scoreboard.

I just don’t get it…it is probably really little mistake that i can’t figure out…


hook.Add( "ScoreboardShow", "whatever", function() return false end )

before the function, I guess it should work.

(Lua kings, please no make fun of me, I am myself still learning)

I’ve made it like this (its probably stupid idea) but it works but i don’t want to get this error:


function GAMEMODE:ScoreboardShow()
	
	hook.Add("HUDPaint", "MyHud", myhud)
	hook.Remove("HUDPaint", "DarkRP_Mod_HUDPaint")

end
function GAMEMODE:ScoreboardHide()

	hook.Remove("HUDPaint", "MyHud")
	hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint", hudPaint)
	
end
function GAMEMODE:HUDDrawScoreBoard()
return true; // Return true to make it allowed.
end

function GM:ScoreboardShow()
	
	hook.Add("HUDPaint", "MyHud", myhud)
	hook.Remove("HUDPaint", "DarkRP_Mod_HUDPaint")

end
function GM:ScoreboardHide()

	hook.Remove("HUDPaint", "MyHud")
	hook.Add("HUDPaint", "DarkRP_Mod_HUDPaint", hudPaint)
	
end
function GM:HUDDrawScoreBoard()
return true; // Return true to make it allowed.
end

If the hook doesn’t work, http://forum.facepunch.com/showthread.php?t=1315439 this could maybe fix it for you.

It works, but when i change GM to GAMEMODE after editing the file it just is not showing my scoreboard anymore its back to that default sandbox scoreboard

Mm, move your sandbox scoreboard to your desktop(so it’s not in the sandbox folder anymore) and then try restarting the server and editing your darkrp scoreboard, see if that does the job.

Just do it like this, same with ScoreboardHide.

[lua]
hook.Add(“ScoreboardShow”, “YourHookName”, function()

 --Your scoreboard here

 return true

end
[/lua]

The issue is you’re including that file after GM has loaded. GM as a variable only exists during Auto-Refresh and on Initialization. If you don’t load a script in that period, then GM becomes GAMEMODE and GM then gets nulled.

Show us how you’re including the file.