Skip to content

Commit 480a588

Browse files
committed
Docs
1 parent a21e108 commit 480a588

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

docs/intro.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@ The Package folder created by Wally should be synced into Roblox Studio through
4242
The Observers module can now be used in scripts, such as the following:
4343
```lua
4444
local ReplicatedStorage = game:GetService("ReplicatedStorage")
45-
4645
local Observers = require(ReplicatedStorage.Packages.Observers)
46+
local observeTag = Observers.observeTag
4747

48-
Observers.observeTag("SomeTag", function(instance: Instance)
48+
observeTag("SomeTag", function(instance: Instance)
4949
print(`Observing {instance}`)
5050
return function()
5151
print(`Stopped observing {instance}`)

lib/index.d.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ interface Observers {
2626
observeAttribute: (
2727
instance: Instance,
2828
name: string,
29-
callback: (value: AttributeValue) => () => void,
29+
callback: (value: AttributeValue) => (() => void) | void,
3030
guard?: (value: AttributeValue) => boolean,
3131
) => () => void;
3232

@@ -53,7 +53,7 @@ interface Observers {
5353
observeProperty: <T extends Instance, P extends InstancePropertyNames<T>>(
5454
instance: T,
5555
property: P,
56-
callback: (value: T[P]) => () => void,
56+
callback: (value: T[P]) => (() => void) | void,
5757
) => () => void;
5858

5959
/**
@@ -99,7 +99,7 @@ interface Observers {
9999
observePlayer: (callback: (player: Player) => ((exitReason: Enum.PlayerExitReason) => void) | void) => () => void;
100100

101101
/**
102-
* Observers characters in the game.
102+
* Observers characters in the game. An optional list of `allowedPlayers` can be provided. Otherwise, characters from all players are observed.
103103
*
104104
* ```ts
105105
* Observers.observeCharacter((player, character) => {
@@ -130,7 +130,25 @@ interface Observers {
130130
*/
131131
observeCharacter: <C extends Model = Model>(
132132
callback: (player: Player, character: C) => (() => void) | void,
133+
allowedPlayers?: Player[],
133134
) => () => void;
135+
136+
/**
137+
* Observers the local character in the game. This can only be called from the client.
138+
*
139+
* ```ts
140+
* observeLocalCharacter((character) => {
141+
* print("Local character added");
142+
* return () => {
143+
* print("Local character removed");
144+
* };
145+
* });
146+
* ```
147+
*
148+
* @param callback Observer called for the local character. Optional cleanup function can be returned, which is called when the character is removed.
149+
* @returns Cleanup function, which stops observing the local character.
150+
*/
151+
observeLocalCharacter: <C extends Model = Model>(callback: (character: C) => (() => void) | void) => () => void;
134152
}
135153

136154
declare const Observers: Observers;

0 commit comments

Comments
 (0)