How to create proximity chat

Hello fellow devs! I had a question on how to create a similar effect i saw in the video down below.

I haven’t found anything on this topic so i would enjoy some assistance if anyone wants :slight_smile:

This is for an upcoming horror game i am working on and I’m trying to achieve realism and immersion this would really help.

1 Like

Use magnitude to check the distance of players from eachother

If player is near certain distance, set it to be opaque (transparency 0)
if player is not quite so near but still in range, set transparency to slightly lower (transparency 0.5)
if player is not near and out of range, do not let player see message and notify that nobody has heard said player (if no player is in range).

And you can do vice versa around.

could you provide an example? i have never worked with magnitude… does this mean the player is the part or what??

–Get the humanoid first

local player = game.Players.LocalPlayer

local char = player.Character or player.CharacterAdded:Wait()

local humanoidrootpart = char:WaitForChild(“HumanoidRootPart”)

local magnitude = (humanoidrootpart.Position - NameHere.Position).Magnitude – change name here to the name of the part

if magnitude <= 10 then – change 10 to any number in for eg. 20 studs away

– what you want to happen

end

this is a module script in chat right??

i’m not that good with magnitude so the code should be made a local script inside of starter gui

i found a post with a script but i dont think it could help me at all

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