// Tag a weaponadd_tag("game.Workspace.Sword", "Weapon")// Tag an enemyadd_tag("game.Workspace.Zombie", "Enemy")// Tag a collectibleadd_tag("game.Workspace.Coin", "Collectible")
// Tag a sword with multiple categoriesconst swordPath = "game.Workspace.Sword";add_tag(swordPath, "Weapon");add_tag(swordPath, "Melee");add_tag(swordPath, "Legendary");add_tag(swordPath, "TwoHanded");
Tags integrate with Roblox’s CollectionService API:
-- Lua script listening for tagged instanceslocal CollectionService = game:GetService("CollectionService")-- Get all instances with "Weapon" taglocal weapons = CollectionService:GetTagged("Weapon")for _, weapon in pairs(weapons) do print("Found weapon:", weapon.Name)end-- Listen for new tagged instancesCollectionService:GetInstanceAddedSignal("Enemy"):Connect(function(instance) print("New enemy spawned:", instance.Name)end)
Adding a tag that already exists does NOT throw an error:
// Add tag twiceadd_tag("game.Workspace.Part", "Weapon");add_tag("game.Workspace.Part", "Weapon"); // No error, no duplicate// Part still has only one "Weapon" tagget_tags("game.Workspace.Part");// Returns: { "tags": ["Weapon"] }
// Tag all parts in a model based on their propertiesconst modelPath = "game.Workspace.WeaponRack";const children = get_instance_children(modelPath);children.forEach(childPath => { // Get part properties const props = get_instance_properties(childPath); // Tag based on class if (props.ClassName === "Part") { add_tag(childPath, "PhysicsPart"); } // Tag based on properties if (props.CanCollide === false) { add_tag(childPath, "NonCollidable"); } // Tag based on attributes const damage = get_attribute(childPath, "Damage"); if (damage && damage > 50) { add_tag(childPath, "HighDamage"); }});