[FAST THREAD] Addon Help

I’ve been out of the loop for a while and I can’t seem to get autorun to work for this addon. I’m trying to create a simple greentexting addon to work for my server. I’ve tested the addon in singleplayer by dropping the script “greentext.lua” in garrysmod/lua/autorun/client/ and it worked perfectly. However, when I create a folder named “Greentext” in the addon folder and have the following two files:

/garrysmod/addons/Greentext/lua/autorun/server/init.lua:



AddCSLuaFile("autorun/client/greentext.lua")


/garrysmod/addons/Greentext/lua/autorun/client/greentext.lua:



function GAMEMODE:OnPlayerChat( player, strText, bTeamOnly, bPlayerIsDead )
	
	--
	-- I've made this all look more complicated than it is. Here's the easy version
	--
	-- chat.AddText( player, Color( 255, 255, 255 ), ": ", strText )
	--
	
	local tab = {}

	
	if ( bPlayerIsDead ) then
	table.insert( tab, Color( 255, 30, 40 ) )
	table.insert( tab, "*DEAD* " )
	end
	
	if ( bTeamOnly ) then
	table.insert( tab, Color( 30, 160, 40 ) )
	table.insert( tab, "( TEAM ) " )
	end
	
	if ( IsValid( player ) ) then
	table.insert( tab, player )
	else
	table.insert( tab, "Console" )
	end
	
	table.insert( tab, Color( 255, 255, 255 ) )
	table.insert( tab, ": ")
	if (string.sub(strText,1,1) == ">") then
		table.insert( tab, Color( 120, 153, 34 ) )
	end
	table.insert( tab, strText)
	chat.AddText( unpack( tab ) )

	return true
	
end


I get an error “attempt to index global ‘GAMEMODE’ (a nil value).” at line 1 of greentext.lua. I’ve already tried switching GAMEMODE to GM but that hasn’t changed anything. I would love if somebody could quickly help me out.

Use hooks instead.

Wow, I’m an idiot. This worked. May 72 virgins be with you.