[FIXED] Whispering does not work due to ProximityChat

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Proximity Chat with available whispering.

  2. What is the issue? I’m using @TheGamer101’s ProximityChat.lua to have local chat in my game, but it seems to be breaking other aspects such as whispering, unfortunately.

  3. What solutions have you tried so far? Modifying ProximityChat.lua, which doesn’t seem to be working, modifying whispering scripts which don’t seem to be working either.

For your knowledge, I’m using LegacyChatService due to personal preferences.

--	// 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 ChatConstants = require(ReplicatedModules:WaitForChild("ChatConstants"))

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 speakerObj and channelObj then
			local playerObj = speakerObj:GetPlayer()
			if playerObj then
				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
			else
				return false
			end
		else
			return false
		end

		return true
	end

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

return Run

Fixed by passing a check if speaker is in the private chat

1 Like