### Install RbxObservers via Wally Source: https://github.com/sleitnick/rbxobservers/blob/main/README.md Add the library to your Wally configuration file. This allows the package to be managed as a dependency within the Roblox environment. ```toml [package] name = "your_name/your_project" version = "0.1.0" registry = "https://github.com/UpliftGames/wally-index" realm = "shared" [dependencies] Observers = "sleitnick/observers@^0.4.0" ``` -------------------------------- ### Install RbxObservers via npm for roblox-ts Source: https://github.com/sleitnick/rbxobservers/blob/main/README.md Add the library to your project using npm. You can either update your package.json file directly or use the command line interface to install the dependency. ```json { "dependencies": { "@rbxts/observers": "^0.4.0" } } ``` ```sh npm i --save @rbxts/observers ``` -------------------------------- ### Basic Observers Usage Example Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/intro.md A Lua script demonstrating how to require the Observers module from ReplicatedStorage and use the observeTag function to observe instances with a specific tag. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local Observers = require(ReplicatedStorage.Packages.Observers) local observeTag = Observers.observeTag observeTag("SomeTag", function(instance: Instance) print(`Observing {instance}`) return function() print(`Stopped observing {instance}`) end end) ``` -------------------------------- ### Install Observers with npm for roblox-ts Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/intro.md Command to install the @rbxts/observers package using npm, suitable for projects using roblox-ts. ```sh npm i --save @rbxts/observers ``` -------------------------------- ### Rojo Configuration for Packages Folder Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/intro.md An example Rojo configuration file to sync the 'Packages' folder, created by Wally, into Roblox Studio's ReplicatedStorage. ```json { "name": "rbx-util-example", "tree": { "$className": "DataModel", "ReplicatedStorage": { "$className": "ReplicatedStorage", "Packages": { "$path": "Packages" } } } } ``` -------------------------------- ### Observer for State Lifetime Management in Lua Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/observer-pattern.md Illustrates how the observer pattern can be used to manage the lifecycle of a state, specifically in a game development context. This example observes a 'Disco' tag on a part and starts flashing its color. A cleanup function is returned to disconnect the flashing effect when the tag is removed or the part is destroyed. ```lua observeTag("Disco", function(part) -- Start flashing the part random colors every frame: local heartbeat = RunService.Heartbeat:Connect(function() part.Color = Color3.new(math.random(), math.random(), math.random()) end) -- Stop flashing on cleanup: return function() heartbeat:Disconnect() end end) ``` -------------------------------- ### Event-Driven Signal Connection in Lua Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/observer-pattern.md Shows a basic example of event-driven programming in Lua using GetPropertyChangedSignal. This connects a function to be called whenever the 'Color' property of a part changes. It differs from the observer pattern by not inherently handling the initial state or the lifetime of the observed state. ```lua part:GetPropertyChangedSignal("Color"):Connect(function() ... end) ``` -------------------------------- ### Observe Character Lifespan and Humanoid Events Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/characters.md Demonstrates how to monitor character spawning and removal. It also shows how to handle humanoid death events by returning a cleanup function to disconnect listeners. ```lua Observers.observeCharacter(function(player, character) print("Character spawned for " .. player.Name) local humanoid = character:WaitForChild("Humanoid", 60) local onDiedConn: RBXScriptConnection? = nil if humanoid then onDiedConn = humanoid.Died:Connect(function() print("Character died for " .. player.Name) end) end return function() print("Character removed for " .. player.Name) if onDiedConn then onDiedConn:Disconnect() onDiedConn = nil end end end) ``` -------------------------------- ### Observe CollectionService Tags with Lifecycle Cleanup Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/tags.md Demonstrates how to observe instances with a specific tag and return a cleanup function to stop processes when the instance or tag is removed. This pattern is essential for preventing memory leaks in dynamic object behaviors. ```lua Observers.observeTag("Disco", function(part: BasePart) local discoThread = task.spawn(function() while true do task.wait(0.2) part.Color = Color3.new(math.random(), math.random(), math.random()) end end) return function() task.cancel(discoThread) end end) ``` -------------------------------- ### Basic Observer Implementation in Lua Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/observer-pattern.md Demonstrates the fundamental structure of an observer function in Lua. It accepts parameters, a callback function that receives the current state, and returns a cleanup function. The returned cleanup function is invoked when the observed state changes or when the observer is explicitly stopped. ```lua local stopObserving = observeSomething(..., function(state) -- Do something with "state". This runs every time state changes, including the initial state. return function() -- Cleanup. Called once "state" changes to something else, or the `stopObserving` function is called. end end) -- At anytime, the `stopObserving` function can be called to stop the above observer and clean up -- and currently-existing observations: stopObserving() ``` -------------------------------- ### Type Casting and Runtime Validation Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/attributes.md Shows how to use Luau generics to hint at expected attribute types and how to implement manual runtime type checking using assertions to ensure data integrity. ```lua Observers.observeAttribute(myInstance, "MyAttribute", function(value: string) assert(typeof(value) == "string", "expected string for MyAttribute; got " .. typeof(value)) -- Process string value end) ``` -------------------------------- ### Observe Roblox entities and state with RbxObservers Source: https://context7.com/sleitnick/rbxobservers/llms.txt Demonstrates how to use RbxObservers to track tagged instances, attributes, player sessions, and character lifecycles. Each observer returns a cleanup function to handle resource disposal when the entity is removed or the observer is stopped. ```typescript import Observers from "@rbxts/observers"; // Observe tagged instances const stopTagObserver = Observers.observeTag("Disco", (part) => { const heartbeat = game.GetService("RunService").Heartbeat.Connect(() => { part.Color = new Color3(math.random(), math.random(), math.random()); }); return () => { heartbeat.Disconnect(); }; }); // Observe attributes with type safety Observers.observeAttribute(workspace.WaitForChild("Model"), "Score", (value) => { print(`Score: ${value}`); return () => { print("Score changed"); }; }); // Observe players Observers.observePlayer((player) => { print(`${player.Name} joined`); return (exitReason) => { print(`${player.Name} left: ${exitReason.Name}`); }; }); // Observe characters Observers.observeCharacter((player, character) => { print(`Character spawned for ${player.Name}`); const humanoid = character.WaitForChild("Humanoid", 60) as Humanoid | undefined; let diedConnection: RBXScriptConnection | undefined; if (humanoid !== undefined) { diedConnection = humanoid.Died.Connect(() => { print(`${player.Name}'s character died`); }); } return () => { diedConnection?.Disconnect(); }; }); ``` -------------------------------- ### Observe Player Lifecycle - Lua Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes players entering and leaving the game. The cleanup callback receives the player's exit reason when they leave or when the observer is stopped. It allows for setting up player-specific data and cleanup routines. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local Observers = require(ReplicatedStorage.Packages.Observers) -- Observe all players joining and leaving local stopObserving = Observers.observePlayer(function(player: Player) print(player.Name .. " entered the game") -- Set up player data, leaderstats, etc. local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Value = 0 coins.Parent = leaderstats -- Cleanup when player leaves return function(reason: Enum.PlayerExitReason) print(player.Name .. " left the game | Reason: " .. reason.Name) -- Save player data before cleanup -- DataStore:SetAsync(player.UserId, playerData) end end) -- Stop observing all players when done stopObserving() ``` -------------------------------- ### Observe Instance Tags with CollectionService (Lua) Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes instances tagged with specified CollectionService tags. It triggers for existing and future tagged instances. The cleanup function runs when the tag is removed or the instance is destroyed. Supports optional ancestor filtering. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local RunService = game:GetService("RunService") local Observers = require(ReplicatedStorage.Packages.observers) -- Observe all instances tagged with "Disco" and make them flash colors local stopObserving = Observers.observeTag("Disco", function(part: BasePart) -- Type check the instance assert(part:IsA("BasePart"), "expected BasePart") -- Start flashing colors every frame local heartbeat = RunService.Heartbeat:Connect(function() part.Color = Color3.new(math.random(), math.random(), math.random()) end) -- Cleanup when tag is removed or instance is destroyed return function() heartbeat:Disconnect() end end) -- Optionally restrict to specific ancestors (only observe within workspace) local allowedAncestors = { workspace } Observers.observeTag("Enemy", function(enemy: Model) print("Enemy spawned:", enemy.Name) return function() print("Enemy removed:", enemy.Name) end end, allowedAncestors) -- Stop all observations when needed stopObserving() ``` -------------------------------- ### Observe Player Lifecycle Events Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/players.md This snippet demonstrates how to use Observers.observePlayer to track when a player enters the game and handle their exit. The returned function acts as a destructor, receiving the exit reason when the player leaves or the observer is cleaned up. ```lua Observers.observePlayer(function(player) print(player.Name .. " entered game") return function(reason) print(player.Name .. " left game") print(`{player.Name} left game (or observer stopped) | reason: {reason.Name}`) end end) ``` -------------------------------- ### observePlayer API Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes players entering and leaving the game. The cleanup callback receives the player's exit reason when they leave or when the observer is stopped. ```APIDOC ## observePlayer ### Description Observes players entering and leaving the game. The cleanup callback receives the player's exit reason when they leave or when the observer is stopped. ### Method `Observers.observePlayer(callback)` ### Parameters #### Callback Function - **callback** (function) - Required - A function that is called when a player enters the game. It receives the `Player` object as an argument and should return a cleanup function. - **player** (Player) - The player who entered the game. - **Returns**: A function that is called when the player leaves or the observer is stopped. It receives `reason` (Enum.PlayerExitReason) as an argument. ### Request Example ```lua local stopObserving = Observers.observePlayer(function(player: Player) print(player.Name .. " entered the game") -- Setup player data, leaderstats, etc. local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = player local coins = Instance.new("IntValue") coins.Name = "Coins" coins.Value = 0 coins.Parent = leaderstats -- Cleanup when player leaves return function(reason: Enum.PlayerExitReason) print(player.Name .. " left the game | Reason: " .. reason.Name) -- Save player data before cleanup end end) -- Stop observing all players when done stopObserving() ``` ### Response - **stopObserving** (function) - A function that, when called, stops the player observation and executes the cleanup functions for all currently connected players. ``` -------------------------------- ### Observe Character Lifecycle Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/characters.md Observes the lifecycle of characters in the game, including spawning, death, and removal. It provides callbacks for each event and allows for cleanup actions. ```APIDOC ## observeCharacter ### Description Observes the lifecycle of characters in the game. This function takes a callback that is executed when a character spawns and returns a cleanup function that is executed when the character is removed. ### Method Observer ### Endpoint N/A (Client-side function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **callback** (function) - Required - A function that accepts `player` and `character` as arguments. This function is called when a character spawns. It should return a cleanup function to be called when the character is removed. - **players** (table) - Optional - A table of player objects. If provided, the observer will only trigger for characters belonging to these players. ### Request Example ```lua Observers.observeCharacter(function(player, character) -- Character was spawned print("Character spawned for " .. player.Name) -- Wait for humanoid: local humanoid = character:WaitForChild("Humanoid", 60) -- Listen to humanoid Died event: local onDiedConn: RBXScriptConnection? = nil if humanoid then onDiedConn = humanoid.Died:Connect(function() print("Character died for " .. player.Name) end) end return function() -- Character was removed print("Character removed for " .. player.Name) if onDiedConn then onDiedConn:Disconnect() onDiedConn = nil end end end) ``` ### Response #### Success Response (Callback Execution) - The callback function provided is executed when a character spawns. - The cleanup function returned by the callback is executed when the character is removed. #### Response Example (No direct response, but callbacks are executed) ### Error Handling - If the `Humanoid` is not found within 60 seconds, the `onDiedConn` will not be set up. - Ensure proper disconnection of events in the cleanup function to prevent memory leaks. ``` -------------------------------- ### Observe Instance Attribute Changes Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/attributes.md Demonstrates how to observe a specific attribute on a Roblox instance. The observer function returns a cleanup function that triggers when the attribute is removed or changed. ```lua Observers.observeAttribute(myInstance, "MyAttribute", function(value) print("Attribute is", value) return function() print("Attribute is no longer", value) end end) ``` -------------------------------- ### Implementing Attribute Guards Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/attributes.md Explains how to use a guard function to filter attribute updates. The observer only executes if the guard function returns a truthy value, effectively acting as a runtime type filter. ```lua Observers.observeAttribute( myInstance, "MyAttribute", function(value: string) print("value is a string", value) end, function(value: unknown) return typeof(value) == "string" end ) ``` -------------------------------- ### Observe Specific Players' Characters Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/characters.md Shows how to filter character observation to a specific subset of players by passing an array of player objects as the second argument. ```lua Observers.observeCharacter(function(player, character) -- Logic for specific players end, { somePlayer, anotherPlayer }) ``` -------------------------------- ### Observe Instance Properties (Lua) Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes a property on an instance, triggering for the current value and all future changes. The cleanup function runs whenever the property value changes. This is useful for reacting to changes in properties like Name or Color. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local Observers = require(ReplicatedStorage.Packages.observers) local targetPart = workspace:WaitForChild("TargetPart") -- Observe the Name property local stopObserving = Observers.observeProperty(targetPart, "Name", function(name: string) print("Name is now:", name) -- Update UI label local label = script.Parent.NameLabel label.Text = name return function() print("Name changed from:", name) end end) -- Observe the Color property of a part Observers.observeProperty(targetPart, "Color", function(color: Color3) print("Color changed to:", color) -- Mirror color to another part local mirrorPart = workspace.MirrorPart mirrorPart.Color = color return function() -- Cleanup when color changes again end end) -- Stop observing when done stopObserving() ``` -------------------------------- ### Observe Character Lifecycle - Lua Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes the lifecycle of player characters (spawning and despawning). Useful for setting up character-specific behaviors and connections that need cleanup when the character is removed. Can observe all characters or a specific subset. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local Observers = require(ReplicatedStorage.Packages.Observers) -- Observe all player characters local stopObserving = Observers.observeCharacter(function(player: Player, character: Model) print("Character spawned for " .. player.Name) -- Wait for humanoid local humanoid = character:WaitForChild("Humanoid", 60) :: Humanoid? -- Track connections for cleanup local connections: {RBXScriptConnection} = {} if humanoid then -- Listen for death table.insert(connections, humanoid.Died:Connect(function() print(player.Name .. "'s character died") end)) -- Listen for health changes table.insert(connections, humanoid:GetPropertyChangedSignal("Health"):Connect(function() print(player.Name .. " health:", humanoid.Health) end)) end -- Cleanup when character is removed return function() print("Character removed for " .. player.Name) for _, conn in connections do conn:Disconnect() end end end) -- Observe only specific players' characters local vipPlayers = { game.Players:WaitForChild("Player1") } Observers.observeCharacter(function(player: Player, character: Model) -- Only triggers for players in the vipPlayers list print("VIP character spawned:", player.Name) return function() print("VIP character removed:", player.Name) end end, vipPlayers) -- Stop observing when done stopObserving() ``` -------------------------------- ### Observe Instance Property Changes Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/properties.md Uses the observeProperty function to monitor a specific property on a Roblox instance. The callback function receives the new value and returns an optional cleanup function that runs when the property changes again or the observer is disconnected. ```lua Observers.observeProperty(workspace.Model, "Name", function(name) print("Name is now: " .. name) return function() print("Name is no longer: " .. name) end end) ``` -------------------------------- ### Observe Local Character Lifecycle - Lua Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes the local player's character lifecycle. This function can only be called from client-side scripts. Ideal for setting up local character controls, camera behaviors, and client-side effects. ```lua -- LocalScript (client-side only) local ReplicatedStorage = game:GetService("ReplicatedStorage") local Observers = require(ReplicatedStorage.Packages.Observers) -- Observe the local player's character local stopObserving = Observers.observeLocalCharacter(function(character: Model) print("Local character has spawned") -- Set up camera follow local humanoidRootPart = character:WaitForChild("HumanoidRootPart") local camera = workspace.CurrentCamera camera.CameraSubject = humanoidRootPart -- Set up local effects local humanoid = character:WaitForChild("Humanoid") :: Humanoid local runningConnection = humanoid.Running:Connect(function(speed: number) if speed > 0 then -- Player is moving, add footstep sounds or effects end end) -- Cleanup when local character is removed return function() print("Local character has been removed") runningConnection:Disconnect() end end) -- Stop observing when no longer needed stopObserving() ``` -------------------------------- ### Validate Instance Types in Observers Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/tags.md Ensures that the observed instance matches the expected class type using IsA. This prevents runtime errors when the observer receives an instance that does not support the expected properties or methods. ```lua Observers.observeTag("Disco", function(part: BasePart) assert(part:IsA("BasePart"), "expected part") end) ``` -------------------------------- ### Observe Instance Attributes (Lua) Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes a specific attribute on an instance. Triggers when the attribute is set to a non-nil value and provides cleanup when the value changes or becomes nil. Supports optional guard predicates for runtime type checking. ```lua local ReplicatedStorage = game:GetService("ReplicatedStorage") local Observers = require(ReplicatedStorage.Packages.observers) local myModel = workspace:WaitForChild("MyModel") -- Basic attribute observation local stopObserving = Observers.observeAttribute(myModel, "Health", function(value: number) print("Health is now:", value) -- Update health bar UI, etc. local healthBar = script.Parent.HealthBar healthBar.Size = UDim2.new(value / 100, 0, 1, 0) return function() print("Health changed from:", value) end end) -- With guard function for type safety Observers.observeAttribute( myModel, "PlayerName", function(value: string) -- This only runs if guard returns true print("Player name is a valid string:", value) end, function(value: unknown) -- Guard ensures value is a non-empty string return typeof(value) == "string" and #value > 0 end ) -- Stop observing when done stopObserving() ``` -------------------------------- ### Observe Local Character Lifespan in Roblox Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/localcharacter.md This snippet demonstrates how to use observeLocalCharacter to execute logic when the local player's character spawns and when it is removed. The provided callback function returns a cleanup function that triggers upon character removal. ```lua Observers.observeLocalCharacter(function(character) print("Local character has spawned") return function() print("Local character has been removed") end end) ``` -------------------------------- ### observeCharacter API Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes the lifecycle of player characters (spawning and despawning). Useful for setting up character-specific behaviors and connections that need cleanup when the character is removed. ```APIDOC ## observeCharacter ### Description Observes the lifecycle of player characters (spawning and despawning). Useful for setting up character-specific behaviors and connections that need cleanup when the character is removed. ### Method `Observers.observeCharacter(callback, playersToObserve)` ### Parameters #### Callback Function - **callback** (function) - Required - A function called when a character spawns or despawns. It receives the `Player` and `character` (Model) as arguments and should return a cleanup function. - **player** (Player) - The player whose character is being observed. - **character** (Model) - The character model that spawned or despawned. - **Returns**: A function that is called when the character is removed or the observer is stopped. #### Players to Observe (Optional) - **playersToObserve** (table) - Optional - A table of `Player` objects to observe. If not provided, all players' characters will be observed. ### Request Example ```lua -- Observe all player characters local stopObservingAll = Observers.observeCharacter(function(player: Player, character: Model) print("Character spawned for " .. player.Name) -- Setup character-specific logic local humanoid = character:WaitForChild("Humanoid") local connections = {} if humanoid then ttable.insert(connections, humanoid.Died:Connect(function() print(player.Name .. "'s character died") end)) end -- Cleanup when character is removed return function() print("Character removed for " .. player.Name) for _, conn in connections do conn:Disconnect() end end end) -- Observe only specific players' characters local vipPlayers = { game.Players:WaitForChild("Player1") } local stopObservingVIP = Observers.observeCharacter(function(player: Player, character: Model) print("VIP character spawned:", player.Name) return function() print("VIP character removed:", player.Name) end end, vipPlayers) -- Stop observing when done stopObservingAll() stopObservingVIP() ``` ### Response - **stopObserving** (function) - A function that, when called, stops the character observation and executes the cleanup functions for all observed characters. ``` -------------------------------- ### observeAttribute Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/attributes.md Observes an attribute on a Roblox instance and triggers a callback when the value changes. ```APIDOC ## observeAttribute ### Description Observes a specific attribute on a Roblox instance. The observer triggers when the attribute is set to a non-nil value. It supports an optional cleanup function returned by the observer. ### Method Lua Function Call ### Endpoint Observers.observeAttribute(instance, attributeName, callback, [guard]) ### Parameters #### Path Parameters - **instance** (Instance) - Required - The Roblox instance to observe. - **attributeName** (string) - Required - The name of the attribute to track. - **callback** (function) - Required - Function executed when the attribute changes. Receives the new value. - **guard** (function) - Optional - A predicate function that returns true if the observer should trigger. ### Request Example ```lua Observers.observeAttribute(myInstance, "MyAttribute", function(value: string) print("Attribute is", value) return function() print("Attribute is no longer", value) end end) ``` ### Response #### Success Response - **cleanup** (function) - Returns a cleanup function to stop observing the attribute. #### Response Example ```lua -- The returned function stops the observation local stop = Observers.observeAttribute(...) stop() ``` -------------------------------- ### observeLocalCharacter API Source: https://context7.com/sleitnick/rbxobservers/llms.txt Observes the local player's character lifecycle. This function can only be called from client-side scripts. Ideal for setting up local character controls, camera behaviors, and client-side effects. ```APIDOC ## observeLocalCharacter ### Description Observes the local player's character lifecycle. This function can only be called from client-side scripts. Ideal for setting up local character controls, camera behaviors, and client-side effects. ### Method `Observers.observeLocalCharacter(callback)` ### Parameters #### Callback Function - **callback** (function) - Required - A function called when the local player's character spawns or despawns. It receives the `character` (Model) as an argument and should return a cleanup function. - **character** (Model) - The local player's character model that spawned or despawned. - **Returns**: A function that is called when the character is removed or the observer is stopped. ### Request Example ```lua -- LocalScript (client-side only) local stopObserving = Observers.observeLocalCharacter(function(character: Model) print("Local character has spawned") -- Setup camera follow local humanoidRootPart = character:WaitForChild("HumanoidRootPart") local camera = workspace.CurrentCamera camera.CameraSubject = humanoidRootPart -- Setup local effects local humanoid = character:WaitForChild("Humanoid") :: Humanoid local runningConnection = humanoid.Running:Connect(function(speed: number) if speed > 0 then -- Player is moving, add footstep sounds or effects end end) -- Cleanup when local character is removed return function() print("Local character has been removed") runningConnection:Disconnect() end end) -- Stop observing when no longer needed stopObserving() ``` ### Response - **stopObserving** (function) - A function that, when called, stops the local character observation and executes the cleanup function. ``` -------------------------------- ### Filter Tagged Instances by Ancestry Source: https://github.com/sleitnick/rbxobservers/blob/main/docs/Observers/tags.md Limits the scope of tag observation to specific parent containers. By providing an array of allowed ancestors, the observer ignores tagged instances located outside the specified hierarchy. ```lua local allowedAncestors = { workspace } Observers.observeTag( "Disco", function(part: BasePart) -- Logic here end, allowedAncestors ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.