I have a ban GUI and I want to filter the reason text but the scripts I try don’t work:
Script in ServerScriptService:
local admins = {1822194589, 883317228} -- Add your id here
local ds = game:GetService("DataStoreService"):GetDataStore("Bans/Unbans")
game.Players.PlayerAdded:Connect(function(plr)
local data = ds:GetAsync(plr.UserId)
local IsAdmin = false
for i,v in pairs(admins) do
if v == plr.UserId then
IsAdmin = true
local clone = script.BanGui:Clone()
clone.Parent = plr.PlayerGui
end
end
if data then
if IsAdmin == false then
if data[1] == true then
plr:Kick("You have been banned from this experience. Reason: "..data[2])
end
end
end
end)
game.ReplicatedStorage:WaitForChild("Ban/Unban").OnServerEvent:Connect(function(plr, plrtoban, reason, ban)
if ban == "Ban" then
for i,v in pairs(admins) do
if plr.UserId == v then
if game.Players:FindFirstChild(plrtoban) then
if game.Players[plrtoban].UserId ~= plr.UserId then
print(plrtoban.." has been banned!")
game.Players[plrtoban]:Kick("You have been banned from this experience. Reason: "..reason)
ds:SetAsync(game.Players[plrtoban].UserId, {true, reason})
else print("This player is an admin!")
end
else
local players = game:GetService("Players")
local Id = players:GetUserIdFromNameAsync(plrtoban)
if Id ~= plr.UserId then
ds:SetAsync(Id, {true, reason})
print(plrtoban.." has been banned!")
end
end
end
end
elseif ban == "Unban" then
local players = game:GetService("Players")
local Id = players:GetUserIdFromNameAsync(plrtoban)
ds:RemoveAsync(Id)
print(plrtoban.." has been unbanned!")
end
end)
Yea its because i tried those articles and like they didnt work but i do have the code i tried:
local success, errorMessage = pcall(function()
filteredreason = game:GetService("TextService"):FilterStringAsync(reason, plr.UserId)
filteredreason = filteredreason:GetNonChatStringForBroadcastAsync()
end)
if success then
game.Players[plrtoban]:Kick("You have been banned from this experience. Reason: "..filteredreason)
ds:SetAsync(game.Players[plrtoban].UserId, {true, reason})
end
the problem with it tho is that the bans didnt save (i put this where the kicking player part is i believe) and if i spammed the ban button too much it just wouldnt filter and it had random issues
idk if thats what it is but the person banning a player can put in a reason for the ban and I want that reason to be filtered (im using like Roblox’s kick gui thing that you just like have)
local admins = {1822194589, 883317228} -- IDs
local ds = game:GetService("DataStoreService"):GetDataStore("BANSTORE")
local function FilterText(String, UserId)
local Success, Error = pcall(function()
local FilteredTable = game:GetService("TextService"):FilterStringAsync(String, UserId)
return FilteredTable:GetNonChatStringForBroadcastAsync()
end)
if Error then
return ""
end
end
game.Players.PlayerAdded:Connect(function(plr)
local data = ds:GetAsync(plr.UserId)
local IsAdmin = false
for i,v in pairs(admins) do
if v == plr.UserId then
IsAdmin = true
local clone = script.BanGui:Clone()
clone.Parent = plr.PlayerGui
end
end
if data then
if IsAdmin == false then
if data[1] == true then
plr:Kick("You have been banned from this experience. Reason: "..data[2])
end
end
end
end)
game.ReplicatedStorage:WaitForChild("BanEvent").OnServerEvent:Connect(function(plr, plrtoban, reason, ban)
if ban == "Ban" then
for i,v in pairs(admins) do
if plr.UserId == v then
if game.Players:FindFirstChild(plrtoban) then
if game.Players[plrtoban].UserId ~= plr.UserId then
print(plrtoban.." has been banned!")
game.Players[plrtoban]:Kick("You have been banned from this experience. Reason: "..FilterText(reason))
ds:SetAsync(game.Players[plrtoban].UserId, {true, FilterText(reason)})
else
print("This player is an admin!")
end
else
local players = game:GetService("Players")
local Id = players:GetUserIdFromNameAsync(plrtoban)
if Id ~= plr.UserId then
ds:SetAsync(Id, {true, FilterText(reason)})
print(plrtoban.." has been banned!")
end
end
end
end
elseif ban == "Unban" then
local players = game:GetService("Players")
local Id = players:GetUserIdFromNameAsync(plrtoban)
ds:RemoveAsync(Id)
print(plrtoban.." has been unbanned!")
end
end)
Quite honestly I wouldn’t filter it, If you have competent staff you shouldn’t have to worry about them being immature with the ban reasons, Plus you wouldn’t want the ban message to filter over a basic word its gonna end up being
“You’ve been kicked from this experience: Banned until 10/30/2021 - ##### #######, ####### at random people, Being ##### ####### others”
unfiltered text - speed hacking, cursing at random people, Being toxic towards others
I personally don’t recommend filtering ban/kick messages unless it’s a full public message such as a chat message or radio system but if it’s something that is going to be used by trusted users such as your staff only I wouldn’t recommend filtering it.
Hey, don’t use “GetNonChatStringForBroadcastAsync()”.
I recommend doing this instead.
local ChatService = game:GetService("Chat")
local Player -- Make sure you make this variable the player object of whoever used the ban command
local OriginalText = "SomethingThatWouldCensorHere"
local FilteredText = ChatService:FilterStringForBroadcast(OriginalText, Player)
print(FilteredText)
I’ve always used this method, and it works marvelous. It will respect the users account age, so if they’re under 13, and using the ban message things like numbers will be censored, etc. Where as 13+, it’s the other way around. Numbers won’t censor for the admin that sent it.
I hope this helped.
Forgot to mention…
You can also utilize ChatService:FilterStringAsync(OriginalText) so you can filter the string without a player, but according to roblox it has more restrictions. If you can use ChatService:FilterStringForBroadcast() then that would be most ideal.
Update Nevermind I just read over the documentation, and apparently the parameters are the same, only FilterStringAsync requires a playerFrom argument, so just stick to ChatService:FilterStringForBroadcast().