For my new game, I want players to be able to name their characters. Though if the string is inappropriate I don’t want hashtags, I just want it to say ‘Name not appropriate for Roblox.’. I think this would be the most efficient way, though I’m not quite sure.
function isallowed(string)
if string.find(game:GetService("TextService"):FilterStringAsync(string), "#") then
return false
end
end
Instead I should suggest just filtering the string and returning it; A player can type “#” and you might confuse it with an inappropriate statement.
Use the following script:
local TextService = game:GetService("TextService")
local function filterString(filteredText)
local success, errorMessage = pcall(function()
return TextService:FilterStringAsync(text, fromPlayerId)
end)
if not success then
warn("Error filtering text:", text, ":", errorMessage)
-- Put code here to handle filter failure
end
end
I will be using the following code to achieve this.
local TextService = game:GetService("TextService")
local function filterString(filteredText)
local success, errorMessage = pcall(function()
return TextService:FilterStringAsync(text, fromPlayerId)
end)
if not success then
warn("Error filtering text:", text, ":", errorMessage)
-- Put code here to handle filter failure
end
end
local function findAll(str, sub)
local found = 0
local positions = {}
while(found)do
found = found + 1
found = str:find(sub, found)
table.insert(positions, found)
end
return positions
end
local function filter(string)
local filtered = filterString(string)
if filtered then
if findAll(string, "#") ~= findAll(filtered, "#") then
return "Name not appropriate for Roblox."
else
return filtered
end
end
Note when editing filtering does not work, as @deafaultyboii1324 said.
I am unsure if making a test server or team testing does or does not work though.
Thanks, everyone for your help!
I have come to the conclusion that this is the best option:
function isallowed(string, userid)
if game:GetService("TextService"):FilterStringAsync(string, userid):GetNonChatStringForUserAsync(userid) == string then
return true
end
end