Proximity Chat in Roblox

Ive been researching proximity chat in roblox and i have a script that works i just need some tweaking.

My script works i just want to implement something to take it the next level and i dont know how. In the video below the further someone is the more transparent the text is. In my script the chat doesnt show up at all once you reach a certain distance. If i could also add the nobody heard you that would help too.

This is my script i just dont know how to implement the transparency and the notification.

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

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

local PROXIMITY_DISTANCE = 50

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
6 Likes

Couldn’t you do Transparency = torso1.Position - torso2.Position).magnitude / PROXIMITY_DISTANCE for the transparency? (For example, if proximity_distance is 300, and the magnitude is 150, then the transparency will be 150 / 300 = .5, and if magnitude was 300 then the transparency will be 300 / 300 = 1)

Although, you have to make a custom chat gui so you can edit messages text transparency and everything (the default roblox chat does not allow you to set text transparency on messages, they will just turn back to 0 as soon as you change it, sure you can fork this but I’m not sure how.)

And for checking if players can’t hear you, just do if torso1.Position - torso2.Position).magnitude < PROXIMITY_DISTANCE then a text gui will appear for the notifications.

1 Like

okay I created the custom chat but now my proximity feature doesn’t work.

1 Like

Hmm, I would assume it’s because your proximity chat uses the chat instance, probably fork the chat to make it send messages to ur gui. I see that in the video they use a custom chat aswell

1 Like