function Copy( Ent ) local Ents, Constraints = GetAllConstrainedEntitiesAndConstraints( Ent ) local EntTables = {} for k, v in pairs(Ents) do EntTables[ k ] = CopyEntTable( v ) end local ConstraintTables = {} for k, v in pairs(Constraints) do table.insert( ConstraintTables, v ) end return EntTables, ConstraintTables end function GetAllConstrainedEntitiesAndConstraints( ent, EntTable, ConstraintTable ) if ( !ent:IsValid() ) then return EntTable, ConstraintTable end local EntTable = EntTable or {} local ConstraintTable = ConstraintTable or {} EntTable[ ent:EntIndex() ] = ent if ( !constraint.HasConstraints( ent ) ) then return EntTable, ConstraintTable end local ConTable = constraint.GetTable( ent ) for key, constraint in pairs( ConTable ) do local index = constraint.Constraint if ( !ConstraintTable[ index ] ) then // Add constraint to the constraints table ConstraintTable[ index ] = constraint // Run the Function for any ents attached to this constraint for key, ConstrainedEnt in pairs( constraint.Entity ) do EntTable, ConstraintTable = GetAllConstrainedEntitiesAndConstraints( ConstrainedEnt.Entity, EntTable, ConstraintTable ) end end end return EntTable, ConstraintTable end