Help needed for simple script

I am trying to create my first gmod addon, a very simple script, but it doesn’t work. This is what I have now:

function joinmsg ( name )
	PrintMessage( HUD_PRINTTALK, "Player " .. name .. " has connected. Welcome!" )
hook.Add ( "GM:PlayerConnect", "PlayerJoins", joinmsg )

I probably f*cked up. But it’s my first addon. And yes, I looked at the tutorial on the wiki but I find it pretty confusing.

EDIT: Do I have to start the script or not? With a command in the console or something, or does the addon start by itself, like other addons?

Well, I know one thing is wrong, change GM:PlayerConnect to PlayerConnect

GM is a magic table created when the game mode loads that contains game mode functions which are called after the hook system is given a chance to override. When calling or using a hook you should always remove it. It’s just how the wiki documents for some reason.

So in conclusion loose the GM:

It still doesn’t work. Again, do I have to type something to activate it?

EDIT: For some reason it didn’t save, so I’m going to test it now.

firstly the code should be
function joinmsg ( name )
PrintMessage( HUD_PRINTTALK, “Player " … name … " has connected. Welcome!” )
hook.Add ( “PlayerConnect”, “PlayerJoins”, joinmsg )
Secondly you need to run this script somehow on the server. You can do that by placing in the file in the “lua/autorun/server/” folder or the init.lua file on a gamemode or addon.