How to make proximity chat, but only with NPCs

Hello all! I want to know how I could be able to make it so that chat the NPCs send can only be seen by players in a certain radius. To clarify, I want the player’s talking to function as normal, but NPC chat to only be able to be seen by certain people in a distance. (Custom chat?)

If there is no solution to the problem, then I’d also love some help on setting up a chat system where people in a certain radius can only see chat of anyone near them (for both players and NPCs). I did find this post, however some replies say that the system is outdated and does not work.

My base NPC chat code:

local speaker = Chat:AddSpeaker("Dummy") -- Chat is defined above
speaker:JoinChannel("All")
speaker:SetExtraData("NameColor", Color3.fromRGB(255, 0, 0))
speaker:SetExtraData("ChatColor", Color3.fromRGB(255, 0, 0))

while true do
	wait(1)
	speaker:SayMessage("Message", "All")
end

Thanks! All help on this is much appreciated.

Well it seems that the chat system doesn’t know anything about the position of the NPC.

Maybe you could make a channel for each NPC, and add players when they are in proximity. I’m not 100% sure how well this approach would work, but it might.

You could also make a system of custom local NPC chat messages, and send them by RemoteEvent based on proximity. Frankly that is probably what I would do.

1 Like

Just a localscript that listens to a remoteevent and writes a message in the (local player’s) chat when it fires. Then NPCs can send their name and message to the remote-event, but only to players in proximity.

1 Like

Yes. ChatSpeaker:GetChannelList() should give you the current list.

A player is by default added to “System” and “All”.

1 Like