Is there any method to make an NPC be alerted to sounds playing?

Is there any sort of way to make it so an NPC is notified when a sound plays, and to know where it was played? As if there was a monster in a game and whenever you opened a door or such it made a noise and they started coming towards it.

No, but assuming you’re playing the sound by calling the :Play() instance method on it you’d know when the sound was played and where from if the sound is parented to a BasePart instance inside the workspace container. With this information you would determine the distance between the NPC’s model and the BasePart of which the sound is emitting from and act accordingly (do nothing if out of range, script custom behavior if in range).

There are several ways you could do this and I am just throwing ideas out here:

  • You could use a Region3 to grab all sounds within a set area near the NPC
  • You could use a Magnitude check to get all sounds within a radius of the NPC
  • You could use CollectionService and give all detectable sounds a special tag (this is what I would do)

Once you grab all the sounds to listen for, do a sanity check and make sure the sound is parented to a part so you can get the position of the sound, then simply listen for the sound being played.

What i’m thinking now is that i could use an event to alert an NPC to a sound playing, but that could be laggy.