How to filter reason text in a ban GUI?

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)
1 Like

Sorry, what’s the exact issue? I don’t see you trying to filter the text.

If you are looking for a method on how to actually filter it, here’s an entire article written about how to filter text on Roblox.

Text and Chat Filtering (roblox.com)

1 Like

You mean like FilterString?

https://developer.roblox.com/en-us/api-reference/function/Chat/FilterStringAsync

1 Like

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)

This might work.

1 Like

I tried it I did change the BANSTORE back to Bans/Unbans just not to overwrite any existing bans but the entire script broke

Can you send an output log/photo?

1 Like

there were no errors or anything

I don’t see what else I can do then, the code looks to be fine as is. Try looking at a youtube tutorial and then incorporating my FilterText function.

1 Like

yea im gonna try to find a filtered youtube tutorial

Filtering does not work while playtesting in studio and will always return a non-filtered result. Try it in an actual server and see if it works.

1 Like

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.

1 Like

Yea but Roblox says all text must be filtered so I’d rather be safe

Yea i tested in a real server but it broke my whole ban system like it won’t even ban anymore

can you screenshot it ----------------

1 Like

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().

1 Like

Thats actually not true to an extent at least,

As listed above it says strictly

Any displayed text that a developer does not have explicit control over should be filtered.

As long as a normal user doesn’t have access to randomly send unfiltered messages you will be fine.

1 Like

You can check this post maybe.

1 Like