Freeze phys deathrun code help

so I have this script which is suppose to freeze the grenades on the map so they do not fall this is what I have.

The error



[ERROR] lua/autorun/fixphys.lua:1: attempt to index global 'GM' (a nil value)
  1. unknown - lua/autorun/fixphys.lua:1


The Code I use in lua/autorun



function GM:OnEntityCreated( ent )
        if prop:IsWeapon() then
		phys = prop:GetPhysicsObject()
		if phys:IsValid() then
			phys:Sleep()
		else
			print("phys is false!")
		end
	end	
end


Can’t find the error.

I am pretty sure auto-run files are added before the gamemode state is created, or after it is passed. Don’t override core functions in addons, you also have an error in it ( Your arg is ent, but you use prop instead ); use

[lua]hook.Add( “OnEntityCreated”, function( _ent )
if ( IsValid( _ent ) && _ent:IsWeapon( ) ) then
local _phys = _ent:GetPhysicsObject( );

	if ( IsValid( _phys ) ) then
		phys:Sleep( );
		// Consider adding constraints
	else
		print( "phys is false!" );
	end
end

end );[/lua]

Make it into a hook. Don’t use GM functions for what you’re trying to do.

Thanks!