localCollectionService=game:GetService('CollectionService')localcomponents=require(shared.components)localinstance=components.instance-- internal tag-to-component maplocaltags={}-- pawns an entity and attaches components to itlocalfunctionspawn_bound(instance:Instance,component:entity)localentity=world.spawn()world.insert(entity,component)world.insert(entity,instance,instance)instance:SetAttribute('id',id)end-- loads a collection tag as a componentlocalfunctionload_collection(tag:string):entityiftags[tag]thenreturntags[tag]endlocaltag_component=world.spawn()tags[tag]=tag_componentlocalfunctionon_added(instance)spawn_bound(instance,tag_component)endCollectionService:GetInstanceAddedSignal(tag):Connect(on_added)localfunctionon_removed(instance)localid=instance:GetAttribute('serverid')ifidthenworld.despawn(id)endendCollectionService:GetInstanceRemovedSignal(tag):Connect(on_removed)for_,instanceinCollectionService:GetTagged(tag)dospawn_bound(instance,tag_component)endreturntag_componentendreturnload_collection