-
What do you want to achieve?
I’m making a custom proximity-rp based chat system. -
What is the issue?
I had issues with my custom message filter (for changing colors etc…) so I pinpointed the problem by dumbing down the filter and finding out which script is causing it to not work.
The filter actually works just fine, however it is supposed to pass the speaker/sender of the message and it is not because of a ProximityChat module (originally written by @TheGamer101 but slightly modified by me). I have a basic understanding of the Lua Chat System but I can’t figure out why is the ProximityChat module causing the filter function to not be passed the speaker (sender) tomakeLowercase(sender, ...)
-
What solutions have you tried so far?
I tried everything but nothing worked because I can’t wrap my head around why is ProximityChat breaking this due to my basic/poor knowledge of the Lua Chat System.
Here I’m using the Devforum example of a filter function along with the original ProximityChatScript, I have no idea why is it passing nil
as the speaker (sender).
TestFilter (ChatModule):
-- Filter function
local function Run(ChatService)
local function makeLowercase(sender, messageObject, channelName)
print(sender)
messageObject.Message = string.lower(messageObject.Message)
end
ChatService:RegisterFilterMessageFunction("makeLowercase", makeLowercase)
end
return Run
ProximityChat (ChatModule):
-- // 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("HumanoidRootPart")
local torso2 = player2.Character:FindFirstChild("HumanoidRootPart")
if torso1 and torso2 then
return (torso1.Position - torso2.Position).magnitude < PROXIMITY_DISTANCE
end
end
return false
end
local function ProximityChatReplicationFunction(speakerName, message, channelName)
print(speakerName)
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
Chat:
Output:
print(sender)
at Line 4 in TestFilter