'cleanData' Basic Admin Essentials Plugin Function Question

Honestly, very simple question: how do I use it the built-in text filtering? I don’t quite know how it should be used and a search of the internet didn’t prove to be too useful, unless I blatantly missed something on accident. What I’m trying to achieve is setting a TextLabel to some text that the player will include in the command, but I need it to filter first. How can I do this?

Here’s the code I would use it on, if that helps you at all:

TeamBadge.Mainframe.NametagText.Text = table.concat(Args, " ", 4, #Args)

Again, this is all within a Basic Admin Essentials Plugin Script. Thanks in advance!

You’re probably looking for Text Filtering | Documentation - Roblox Creator Hub?

From there, the key is probably to use:
TextService:FilterStringAsync(message, fromPlayerId) -> TextFilterResult
to get a filtered text object and then
textObject:GetNonChatStringForBroadcastAsync() -> string
to get the string to display for anyone
Both require pcall

Here’s an example copied from that documentation (the page has more detail and warnings)

local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local sign = workspace.Sign
local signTop = sign.Top
local signSurfaceGui = signTop.SurfaceGui
local signLabel = signSurfaceGui.SignLabel

local setSignText = ReplicatedStorage.SetSignText

local function getTextObject(message, fromPlayerId)
	local textObject
	local success, errorMessage = pcall(function()
		textObject = TextService:FilterStringAsync(message, fromPlayerId)
	end)

	if success then
		return textObject
	end
	print("Error generating TextFilterResult: ", errorMessage)
	return false
end


local function getFilteredMessage(textObject)
	local filteredMessage
	local success, errorMessage = pcall(function()
		filteredMessage = textObject:GetNonChatStringForBroadcastAsync()
	end)

	if success then
		return filteredMessage
	end
	print("Error filtering message: ", errorMessage)
	return false
end


-- Fired when client sends a request to write on the sign
local function onSetSignText(player, text)
	if text ~= "" then
		-- Filter the incoming message and send the filtered message
		local messageObject = getTextObject(text, player.UserId)
		local filteredText = ""
		filteredText = getFilteredMessage(messageObject)
		signLabel.Text = filteredText
	end
end

setSignText.OnServerEvent:Connect(onSetSignText)
1 Like

I’m aware of this solution, but I was just wondering if BAE had a built-in function for that, kind of like how there’s a a built in function for finding players from an argument from the command (findPlayers()). Would you know anything about this?

Ah, sorry! I totally misunderstood that, for some reason I read that as you were developing a text filtering system for that and unfortunately I don’t know much about BAE so I won’t be too helpful.

Hello,

Allow me to shed some light on this.

local cleanData = Data[1][8] -- cleanData(Sender,Receiver,Data)
	-- Practical example, for a gui specifically for a player, from another player
	-- cleanData(Sender,Receiver,"hi") -- You need receiver because it's being sent to everyone
	-- Or for a broadcast (something everyone sees, from one person, to nobody specific)
	-- cleanData(Sender,nil,"hi") -- Receiver is nil because it is a broadcast

I kindly request that you read the comments on the code that’s already attached to the default Basic Admin plugins; they provide a brief explanation and provide some insight on what they do. Let me know if you have additional questions, and I’ll do my best to assist you further.

I did see this in the script, but I still can’t seem to figure out how to use it correctly in the context I described above in my original post. Would you be able to help with that? Thanks!

Sure, let me try to describe it in an understandable way.

-- cleanData(Sender,nil,"hi") -- Receiver is nil because it is a broadcast

--Sender would be the player executing in this context

So, you’d end up doing the first two arguments and then the string that needs to be treated as a broadcast in this context—you should be all set to go after that.

So I changed the line that sets the text to this:

TeamBadge.Mainframe.NametagText.Text = cleanData(Player, nil, table.concat(Args, " ", 4, #Args))

But now I’m getting a function error from BAE and no output errors. What did I do wrong?
image