Dear Developers,
I am currently making a pet naming system and have stumbled to a error.
How do I make curse words filter out with hashtags?
Here is the script:
local player = game.Players.LocalPlayer
local character = player.Character
script.Parent.MouseButton1Click:Connect(function()
local petname = script.Parent.Parent.Showcase.PetName
local pcpetname = script.Parent.Parent.PetName
local pet = game.ReplicatedStorage.Pets:WaitForChild(petname.Text)
if pet ~= nil then
local opet = character:FindFirstChild("OldPet")
if opet ~= nil then
character.OldPet:Destroy()
pet:Clone().Parent = character
wait(0.1)
local oldpet = character:FindFirstChild(petname.Text)
oldpet.Name = "OldPet"
oldpet.NameGui.PName.Text = pcpetname.Text
elseif opet ~= not nil then
pet:Clone().Parent = character
wait(0.1)
local oldpet = character:FindFirstChild(petname.Text)
oldpet.Name = "OldPet"
oldpet.NameGui.PName.Text = pcpetname.Text
end
end
end)
The TextService Service has a built in function to asynchronously run a given string through the default chat filter: TextServicer:FilterStringAsync() If you are acquiring input locally (client-side), you will need a RemoteEvent to call the function on the Server.
local player = game.Players.LocalPlayer
local character = player.Character
local TextService = game:GetService("TextService")
script.Parent.MouseButton1Click:Connect(function()
local petname = script.Parent.Parent.Showcase.PetName
local pcpetname = script.Parent.Parent.PetName
local pet = game.ReplicatedStorage.Pets:WaitForChild(petname.Text)
if pet ~= nil then
local opet = character:FindFirstChild("OldPet")
if opet ~= nil then
character.OldPet:Destroy()
pet:Clone().Parent = character
wait(0.1)
local oldpet = character:FindFirstChild(petname.Text)
oldpet.Name = "OldPet"
TextServicer:FilterStringAsync(pcpetname)
oldpet.NameGui.PName.Text = pcpetname.Text
elseif opet ~= not nil then
pet:Clone().Parent = character
wait(0.1)
local oldpet = character:FindFirstChild(petname.Text)
oldpet.Name = "OldPet"
TextServicer:FilterStringAsync(pcpetname)
oldpet.NameGui.PName.Text = pcpetname.Text
end
end
end)
Use a remote to send the text to the server. Call TextService:FilterStringAsync(userId, text), passing in the id of the user who sent it and the text that was sent over. You might want to wrap this in a pcall statement since it is asynchronous and dependent on a service which might fail.
It will return a TextFilterResult object. Since I’m assuming the text will be showed to everyone as a pet’s name you should use TextFilterResult:GetNonChatStringForBroadcastAsync(). That will return the filtered string.
Hello blokav, i used your method and roblox´s, and i tried to put in a curse word to check if it works. And it still gave me the curse word. Do you have any idea how that could happen?