function useTagged<T extends Instance>(tag: string): readonly T[];
Tracks and returns all instances assigned to the given CollectionService
tag. Re-renders the component when tagged instances are added or removed from the data model.
tag
- The tag to filter instances for.
- A list of instances with the given tag.
Get all instances with the tag "Zombie"
:
function ZombieHealth() {
const zombies = useTagged("Zombie");
return (
<>
{zombies.map((zombie) => (
<ZombieHealthbar model={zombie} />
))}
</>
);
}
Get all instances with the tag "Zombie"
and cast them to a custom ZombieModel
type:
interface ZombieModel extends Model {
Health: NumberValue;
}
function ZombieHealth() {
const zombies = useTagged<ZombieModel>("Zombie");
return (
<>
{zombies.map((zombie) => (
<ZombieHealthbar model={zombie} />
))}
</>
);
}