How to make a function that determines if text is filtered

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

  1. What do you want to achieve? I want to make a function that returns either true or false whether a message is filtered.

  2. What is the issue? I’ve tried it before but it keeps returning nil

function isallowed(stringg, userid)
	if game:GetService("TextService"):FilterStringAsync(string, userid):GetNonChatStringForUserAsync(userid) == string then
		return true
	else
		return false
	end
end
  1. What solutions have you tried so far? ^
1 Like

Maybe one of these might help -

function isallowed(stringg, userid)
	local filteredText = game:GetService("TextService"):FilterStringAsync(stringg, userid):GetNonChatStringForUserAsync(userid)
	local stringHashtags = 0
	local filteredHashtags = 0;
	for i = 1, #stringg, 1 do
		if stringg:sub(i, i) == "#" then
			stringHashtags += 1
		end
	end
	for i = 1, #filteredText, 1 do
		if stringg:sub(i, i) == "#" then
			filteredHashtags += 1
		end
	end
	if filteredHashtags > stringHashtags then
		return true
	else
		return false
	end
end

Still keeps returning false always

Are you testing in studio or in game. If you’re testing in studio, I think the filter is disabled there. If that was the case then try testing in game.

In game I can send you it if you want

Sure, you can send me a private message or just send the link here.

I just noticed I also made a slight error in my code… It would always return “bad” because I forgot to add = at the > part. But here is the new code.

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild('RemoteEvent')
local TextService = game:GetService('TextService')
function isallowed(stringg, userid)
	local filteredText = game:GetService("TextService"):FilterStringAsync(string, userid):GetNonChatStringForUserAsync(userid)
	local stringHashtags = 0
	local filteredHashtags = 0;
	for i = 1, #stringg, 1 do
		if stringg:sub(i, i) == "#" then
			stringHashtags += 1
		end
	end
	for i = 1, #filteredText, 1 do
		if stringg:sub(i, i) == "#" then
			filteredHashtags += 1
		end
	end
	if filteredHashtags >= stringHashtags then
		return true
	else
		return false
	end
end

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, message)
	message = tostring(message)
	local check = isallowed(message, player.UserId)
	if check == true then
		game.ReplicatedStorage.RemoteEvent:FireClient(player, "good")
	else
		game.ReplicatedStorage.RemoteEvent:FireClient(player, "bad")
	end
end)

Remember though, it will only work in game.

2 Likes

Although this would work but if the player intentionally placed hashtags in their string it could fire this falsely, you could create a variable with the original string and have the filtered string compared and see if anything changed to a hashtag. But this method is also suitable so do what ever pleases you.

I’m not sure what you mean? I have already made the script check if the filtered string has more hashtags than the original string. It should work completely fine…