Spawn a prop on the player

Hi

I’ve just put together code I found on the wiki and made some small changes.

Error:

It spawns but it then just falls on the floor.

Expected:
The prop should be following me on my head if I understood it correctly.



		ply = self.Owner;
		
		function GetOurAttachment( ply )
			local ID = ply:LookupAttachment( "eyes" );
			return ply:GetAttachment( ID );
		end
			 
		function GetHeadPos( ply )
			return GetOurAttachment( ply ).Pos;
		end 
		
		if SERVER then
			local model = ents.Create( "prop_physics" );
			model:SetModel( "models/props_c17/GasPipes006a.mdl" )
			model:SetPos( GetHeadPos( ply ) );
			model:SetAngles( ply:GetAngles() );
			model:Fire( "setparentattachment", "eyes", 0 );
			model:Spawn();
		end


Try using this:


	ply = self.Owner;
		
		--function GetOurAttachment( ply )
			--local ID = ply:LookupAttachment( "eyes" );
			--return ply:GetAttachment( ID );
		--end
			 
		function GetHeadPos( ply )
			return GetOurAttachment( ply ).Pos;
		end 
		
		if SERVER then
			local model = ents.Create( "prop_physics" );
			model:SetModel( "models/props_c17/GasPipes006a.mdl" )
			model:SetPos( GetHeadPos( ply ) );
			model:SetAngles( ply:GetAngles() );
			model:SetParent(ply)
			
			model:Fire("SetParentAttachmentMaintainOffset", "eyes", 0.01)
			model:Spawn();
		end

As Fortune said, you missed SetParent.

Thank you, but I don’t know why you commented out the first function, it works if it isn’t outcommented.