Global chat proximity

Is it possible to set an in-game limit for the distance it takes for players to see bubble chat messages and that message being displayed on the global chat gui?

For example, you can only be within 15 studs to see someones bubble chat message.

5 Likes

You’d have to create a custom replication function like the TeamChat chat module uses. You should be able to find the TeamChatReplicationFunction in Chat.ChatModules.TeamChat and use that as a base for making your own.

There’s a bunch of other code in that module for things like handling team changing and /team commands, but you can just ignore it.

No idea how the bubble chat part actually works. I assume it’d be something with BillboardGuis and setting the max view distance or w/e.

1 Like

I actually made this back when I was working on the chat system at Roblox.

--	// FileName: ProximityChat.lua
--	// Written by: TheGamer101
--	// Description: Only allows players to see messages from those within a certain distance.

local Chat = game:GetService("Chat")
local RunService = game:GetService("RunService")

local ReplicatedModules = Chat:WaitForChild("ClientChatModules")
local ChatSettings = require(ReplicatedModules:WaitForChild("ChatSettings"))

local PROXIMITY_DISTANCE = 100

local function Run(ChatService)
	
	local function WithinProximity(player1, player2) 
		if player1 == player2 then
			return true
		end
		
		if player1.Character and player2.Character then
			local torso1 = player1.Character:FindFirstChild("Torso")
			local torso2 = player2.Character:FindFirstChild("Torso")
			if torso1 and torso2 then
				return (torso1.Position - torso2.Position).magnitude < PROXIMITY_DISTANCE
			end
		end
		return false
	end
	
	local function ProximityChatReplicationFunction(speakerName, message, channelName)
		local speakerObj = ChatService:GetSpeaker(speakerName)
		local channelObj = ChatService:GetChannel(channelName)
		
		if not speakerObj then return false end		
		if not channelObj then return false end		
		
		local playerObj = speakerObj:GetPlayer()
		
		if not playerObj then return false end
		
		for i, otherSpeakerName in pairs(channelObj:GetSpeakerList()) do
			local otherSpeakerObj = ChatService:GetSpeaker(otherSpeakerName)
			if otherSpeakerObj then
				local otherPlayerObj = otherSpeakerObj:GetPlayer()
				if otherPlayerObj then
					if WithinProximity(playerObj, otherPlayerObj) then
						otherSpeakerObj:SendMessage(message, channelName, speakerName, message.ExtraData)
					end
				end
			end
		end

		
		return true
	end

	ChatService:RegisterProcessCommandsFunction("proximity_chat", ProximityChatReplicationFunction, ChatSettings.LowPriority)
end

return Run

No comments so let me know if you want anything explained but it should be easy enough to modify for your purposes.

For just bubble chat you can change MAX_BUBBLE_DISTANCE property in the bubble chat script.

26 Likes

Where do you put this? I would like to use this for upcoming games.

2 Likes

You put it in the ChatModules folder under Chat.
I would recommend installing it like this:

  1. Go into studio
  2. Press Play and copy the ChatModules folder from Chat.
  3. Leave Play and paste the ChatModules folder into Chat.
  4. Delete the other modules in ChatModules but leave the InsertDefaultModules BoolValue. This way you will get any updates to the chat scripts.
  5. Create a new module script and insert that code.
16 Likes

Hey! I’d like to let you know that this apparently no longer works, and I have tested it with a friend, and whatever he is/I’m chatting, doesn’t appear for him or me. I can’t really tell you what’s wrong since nothing appears in the console.

1 Like

It’s probably broken because it’s written for R6 and not R15. It uses the position of “Torso” which doesn’t exist for R15s. Try changing Torso to HumanoidRootPart and that should fix it.

2 Likes

Yup! Thanks, it works now! But for some reason, the messages replicates twice for the person that’s sending the message.

2 Likes

Theres two Bubble Distance properties in roblox’s chat config, yet changing either doesn’t seem to effect the range.