[HELP!] Coding Trouble [New Coder]

Well, I’ve just started coding/scripting for GMod and I’ve been having a problem.

For example, my first coding was:


function GM:PlayerInitialSpawn( ply )
	ply:SetGravity( 1 )
	ply:SetWalkSpeed( 300 )
	ply:SetRunSpeed( 500 )
end

function GM:PlayerSpawn( ply )
	ply:Give( "weapon_crowbar" )

And then, after toying with that for about thirty minutes with no success, I decided “Fuck it, let’s just try something else.” So, I made this code.


function GM:PlayerInitialSpawn( ply )
	ply:Give( "weapon_awp" )
end

function GM:PlayerSpawn( ply )
    ply:Give( "weapon_awp" )
end

Neither seemed to work. Could someone please help, or atleast tell me what I did wrong?

Are you trying to hook these? Try putting something like this in autorun


function DoThisOnFirstSpawn( ply )
   ply:SetGravity( 1 )
   ply:SetWalkSpeed( 300 )
   ply:SetRunSpeed( 500 )
end

hook.Add( "PlayerInitialSpawn", "uniquenamethatdoesntconflictwithanything", DoThisOnFirstSpawn )

Alright, I’ll try this.

You can only access GM functions if you place the code inside the gamemode files. Otherwise, you’ll have to hook “Initialize” and do your functions in there; Initialize gets called after the gamemode loads. As for what he gave, you might want to change it to PlayerSpawn, PlayerInitialSpawn is only called when the player first joins the server, not when they actually spawn.