Code:
unclip()
{
self endon("disconnect");
self endon("killed_player");
self.obj = spawn("script_origin",self.origin, 1);
self.obj.angles = self.angles;
self linkto(self.obj);
self disableweapon();
self iprintlnbold("^7Press ^3[^7MELEE^3]^7 to move!");
wait 0.1;
self iprintlnbold("^7Press ^3[^7F^3]^7 to stop!");
for( ;; )
{
if( self meleebuttonpressed() )
{
thing1 = anglestoforward( self getplayerangles() );
thing2 = maps\mp\_utility::vectorScale( thing1, 11 );
position = self.origin + thing2;
self.obj.origin = position;
}
else if( self usebuttonPressed() )
{
self notify("stop_noclip");
self unlink();
wait( 0.05 );
if( isDefined( self.obj ) )
self.obj delete();
self enableweapon();
}
wait( 0.05 );
}
}
There was technically not much wrong with your code - it was just a question of timing - if a player is linked to any object, allow at least 1 server frame before you delete the object.
FYI - if you end a wait time with "killed_player", there is no point putting further notifications like "spawned" or "spawned_player" because the loop is already ended when you die. Every single time you use endon() it adds to the total amount of script variables you use, and if you use too many, your server will crash.