Setting a players position after the come out of noclip.

[lua]local function Observe( clipper )

if( !clipper:IsAdmin() and !clipper:IsSuperAdmin() ) then 

	return false; 
	
end --No way is a non admin going into observe!

if( !(clipper:GetMoveType() == MOVETYPE_NOCLIP) ) then

	if( clipper:GetActiveWeapon() and clipper:GetActiveWeapon():IsValid() ) then
		clipper:GetActiveWeapon():SetNoDraw( true );
	end

	oldpos = clipper:GetPos()
	clipper:SetNoDraw(true)
	clipper:SetMoveType( MOVETYPE_NOCLIP )
	clipper:GodEnable()
	clipper:SetNotSolid(true)
	clipper:PrintMessage(HUD_PRINTTALK, "Welcome to observe mode. You're now invisible and in noclip, just press noclip again to exit." )
	return

elseif( clipper:GetMoveType() == MOVETYPE_NOCLIP ) then

	if( clipper:GetActiveWeapon() and clipper:GetActiveWeapon():IsValid() ) then
		clipper:GetActiveWeapon():SetNoDraw( false );
	end

	clipper:SetPos( oldpos )
	clipper:SetNotSolid(false)
	clipper:GodDisable()
	clipper:SetMoveType( MOVETYPE_WALK )
	clipper:SetNoDraw(false)
	clipper:PrintMessage(HUD_PRINTTALK, "You're no longer in observe mode. You've been returned to your original position." )
	return
	
end

end

hook.Add(“PlayerNoClip”, “ObserveMode”, Observe)[/lua]

It works as intended, however the player is not moved to their original position.

You’re setting oldpos as a global variable. Instead, do clipper.oldpos = mypos, then :SetPos(clipper.oldpos)

Ahhh… So does putting a period, denote that oldpos is a property of clipper?

Even better, that specific “clipper”/player.

Yeah, it makes it specific to that object.

Right. So I made the changes, and it’s still not working.

Errors?

None. It just drops the player where they leave noclip.

[editline]12:54AM[/editline]

[lua]local function Observe( clipper )

if( !clipper:IsAdmin() and !clipper:IsSuperAdmin() ) then 

	return false; 
	
end --No way is a non admin going into observe!

if( !(clipper:GetMoveType() == MOVETYPE_NOCLIP) ) then

	if( clipper:GetActiveWeapon() and clipper:GetActiveWeapon():IsValid() ) then
		clipper:GetActiveWeapon():SetNoDraw( true );
	end

	clipper.oldpos = clipper:GetPos()
	clipper:SetNoDraw(true)
	clipper:SetMoveType( MOVETYPE_NOCLIP )
	clipper:GodEnable()
	clipper:SetNotSolid(true)
	clipper:PrintMessage(HUD_PRINTTALK, "Welcome to observe mode. You're now invisible and in noclip, just press noclip again to exit." )
	return

elseif( clipper:GetMoveType() == MOVETYPE_NOCLIP ) then

	if( clipper:GetActiveWeapon() and clipper:GetActiveWeapon():IsValid() ) then
		clipper:GetActiveWeapon():SetNoDraw( false );
	end

	clipper:SetPos( clipper.oldpos )
	clipper:SetNotSolid(false)
	clipper:GodDisable()
	clipper:SetMoveType( MOVETYPE_WALK )
	clipper:SetNoDraw(false)
	clipper:PrintMessage(HUD_PRINTTALK, "You're no longer in observe mode. You've been returned to your original position." )
	return
	
end

end[/lua]

Function as of now.

This works for me :
[lua]local function Observe( ply )

if not( ply:IsAdmin() or ply:IsSuperAdmin() ) then return end --No way is a non admin going into observe!

if not ply.OldPos then
    
    if ply:GetActiveWeapon() and ply:GetActiveWeapon():IsValid() then
        ply:GetActiveWeapon():SetNoDraw( true )
    end

    ply:SetNoDraw(true)
    ply.OldPos = ply:GetPos()
    ply:GodEnable()
    ply:PrintMessage(HUD_PRINTTALK, "Welcome to observe mode. You\'re now invisible and in noclip, just press noclip again to exit." )
    
else

    if ply:GetActiveWeapon() and ply:GetActiveWeapon():IsValid() then
        ply:GetActiveWeapon():SetNoDraw( false )
    end

    timer.Simple(0.01,function()
        ply:SetPos( ply.OldPos )
        ply.OldPos = nil
        ply:SetVelocity(ply:GetVelocity() * -1) -- This is to players don't keep their noclip speed.
    end) -- Delaying the SetPos fixes it.

    ply:GodDisable()
    ply:SetNoDraw(false)
    ply:PrintMessage(HUD_PRINTTALK, "You\'re no longer in observe mode. You\'ve been returned to your original position." )
    -- Escaped single quotes in the string, they were causing errors.
end

end

hook.Add(“PlayerNoClip”,“ObserverMode”,Observe)[/lua]

:eng101:

ply:IsAdmin() returns true if they are a superadmin.

The unescaped apostrophes were causing errors. Wow, thanks! And thanks for the little tip Lexic.