You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to make a function that returns either true or false whether a message is filtered.
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
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
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.
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)
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…