I'm trying to make a filter for my custom chat but every time I try to filter something it throws an error.
--LocalScript that send the message to the server local LocalPlayerName = game:GetService("Players").LocalPlayer.Name local Rank = "(Test Rank)" local Text = "im trying to filter this: d7sjfix8snd" --text game:GetService("ReplicatedStorage").SendMessage:FireServer(LocalPlayerName,Rank,Text)
The script above and below work fine
--Script that receives the message game:GetService("ReplicatedStorage").SendMessage.OnServerEvent:Connect(function(PlrWhoSent,Plr,Rank,Message) local TextService = game:GetService("TextService") local Msg = "" local success,err = pcall(function() FilteredString = TextService:FilterStringAsync(Message,PlrWhoSent.UserId) end) if err then warn("Failed to filter text: "..err) Msg = "<Failed To Filter Text>" else Msg = FilteredString end game:GetService("ReplicatedStorage").SendMessage:FireAllClients(Plr,Rank,Msg) end)
This is where the error occurs
--LocalScript that receives the message game:GetService("ReplicatedStorage").SendMessage.OnClientEvent:Connect(function(Plr,Rank,Msg) local FilteredMessage = Msg:GetChatForUserAsync(game:GetService("Players").LocalPlayer.UserId) --[[script.Parent.MessageReady:Fire(FilteredMessage) This sends it to the script that handles the messages]]
I tried looking for a solution, but i didnt find anything.
ok u putted it on server so put it back to client and dont use FireAllClients use FireClient and after that if it work u will use a for and send the message to everyone
I think i fixed it!
Server script:
--Script that receives the message game:GetService("ReplicatedStorage").SendMessage.OnServerEvent:Connect(function(PlrWhoSent,Plr,Rank,Message) local TextService = game:GetService("TextService") local Msg = "" local success,err = pcall(function() FilteredString = TextService:FilterStringAsync(Message,PlrWhoSent.UserId) end) if err then warn("Failed to filter text: "..err) Msg = "<Failed To Filter Text>" else Msg = FilteredString end local FilteredMsg = Msg:GetChatForUserAsync(PlrWhoSent.UserId) game:GetService("ReplicatedStorage").SendMessage:FireAllClients(Plr,Rank,FilteredMsg) end)
Client script:
--LocalScript that send the message to the server local LocalPlayerName = game:GetService("Players").LocalPlayer.Name local Rank = "(Test Rank)" local Text = "im trying to filter this: d7sjfix8snd" --text game:GetService("ReplicatedStorage").SendMessage:FireServer(LocalPlayerName,Rank,Text) game:GetService("ReplicatedStorage").SendMessage.OnClientEvent:Connect(function(Plr,Rank,Msg) warn(Msg) end)