GM A NIL VALUE....

error attempt to index global ‘GM’ (a nil value)

please help my code is

[lua]
surface.CreateFont( “TheDefaultSettings”, {
font = “Arial”,
size = 13,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
function GAMEMODE:PostDrawOpaqueRenderables()
for _, ent in pairs(ents.FindByClass(“npc_jeffery”)) do
cam.Start3D2D(ent:GetPos()+Vector(0,0,90), ent:GetAngles() + Angle(0,90,90), 0.1)
draw.SimpleText(“Hello World!”, “TheDefaultSettings”, 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
end
[/lua]

The code you’ve shown does not use the GM variable, and so that error should not occur.
First of all, you shouldn’t be overriding GAMEMODE hooks, use hook.Add for that. If you ever need to use the GAMEMODE table but are unsure as to whether it’ll be loaded or not, do this
[lua]( GM or GAMEMODE ).myVar[/lua]
If the file is run while the gamemode is loading, GM will be active and will be used, otherwise GAMEMODE will be used because the gamemode is already loaded.

so ive changed it too

[lua]
surface.CreateFont( “TheDefaultSettings”, {
font = “Arial”,
size = 13,
weight = 500,
blursize = 0,
scanlines = 0,
antialias = true,
underline = false,
italic = false,
strikeout = false,
symbol = false,
rotary = false,
shadow = false,
additive = false,
outline = false,
} )
function GM:PostDrawOpaqueRenderables()
for _, ent in pairs(ents.FindByClass(“npc_jeffery”)) do
cam.Start3D2D(ent:GetPos()+Vector(0,0,90), ent:GetAngles() + Angle(0,90,90), 0.1)
draw.SimpleText(“Hello World!”, “TheDefaultSettings”, 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1)
cam.End3D2D()
end
end

hook.Add( “nametag”,“icantcode”, PostDrawOpaqueRenderables )
[/lua]

[editline]28th September 2014[/editline]

would that work
Moit?

[editline]28th September 2014[/editline]

does not work get the same error

Please try searching up examples beforehand
[lua]surface.CreateFont( “TheDefaultSettings”, {
font = “Arial”,
size = 13,
weight = 500,
antialias = true,
} )

hook.Add( “PostDrawOpaqueRenderables”,“youdidnteventry”, function()

for _, ent in pairs(ents.FindByClass("npc_jeffery")) do

	cam.Start3D2D(ent:GetPos()+Vector(0,0,90), ent:GetAngles() + Angle(0,90,90), 0.1)
		
		draw.SimpleText("Hello World!", "TheDefaultSettings", 0, -90, Color(255,0,0,255), TEXT_ALIGN_CENTER, 1) 
	
	cam.End3D2D() 
end

end )[/lua]

thnx but the name tag does not show?

THNX FOR THE HELP btw for even replieing

Damn there’s a space after PostDrawOpaqueRenderables, remove it.

no there isnt?

[editline]28th September 2014[/editline]

im confused.

I accidentally added a space to the end of "PostDrawOpaqueRenderables ", remove it.

there is not a space? “PostDrawOpaqueRenderables” i must be blind?

I already fixed my post.

thankyou :slight_smile:

[editline]28th September 2014[/editline]

works!