Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to filter string inside of this script?

I don't get how to filter. I've tried but I had no success. I also posted a question about it before but nobody responded at all. Here's my script:

local UIS = game:GetService("UserInputService")
local chatbar = script.Parent

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.Slash then
		chatbar:CaptureFocus()
	end
end)

chatbar.FocusLost:connect(function(EnterPressed)
	if EnterPressed and chatbar.Text ~= "" and chatbar.Text ~= " " then
		
		local message = chatbar.Text
		local plr = chatbar.Parent.Parent.Parent
		local chatstorage = game.Workspace:WaitForChild("ChatStorage")
		local plrmessage = Instance.new("StringValue", chatstorage)
		
		plrmessage.Value = plr.Name..": "..message

		wait(0.1)
		chatbar.Text = "Press \"/\" to chat!"
	end
end)

This is for a custom chat that I'm making. Can someone help?

1 answer

I know how sad it can be when your game gets locked because the custom chat is not filtered. Here:

local UIS = game:GetService("UserInputService")
local chatbar = script.Parent

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.Slash then
        chatbar:CaptureFocus()
    end
end)

chatbar.FocusLost:connect(function(EnterPressed)
    if EnterPressed and chatbar.Text ~= "" and chatbar.Text ~= " " then

        local message = chatbar.Text
        local plr = chatbar.Parent.Parent.Parent
        local chatstorage = game.Workspace:WaitForChild("ChatStorage")
        local plrmessage = Instance.new("StringValue", chatstorage)

        plrmessage.Value = plr.Name..": "..game.Chat:FilterStringForBroadcast(message, plr)

        wait(0.1)
        chatbar.Text = "Press \"/\" to chat!"
    end
end)

The code will filter it for broadcast. (which is a filtering that is as strict as the filtering for safe chatters) If you define the recipient, you are able to do FilterStringAsync (which will filter the string according to the recipient's security settings.) A great explanation: http://wiki.roblox.com/index.php?title=Text_Filtering

3 comments

0

You should use game.GetService("Chat") just to make sure it won't break if for some reason Chat hasn't been loaded into the place yet.

0

The chat still works the same way -- works perfectly but without filtering. I know this because when I say stuff that roblox would filter, like "oder" or numbers, it didn't get hashtagged

0

It only filters in online servers, not in Studio.

This discussion is preserved as it was. New answers, comments, and votes are closed.