Need help with FilterStringAsync

Hello! I’m trying to make a “bio” system, like Roblox’s about page, but I can’t figure out how to make it work. It’s giving me this error:
image
Client:

script.Parent.Submit.MouseButton1Click:Connect(function()

game.ReplicatedStorage.Bio:FireServer(script.Parent.Bio)

end)

Server:

game.ReplicatedStorage.Bio.OnServerEvent:Connect(function(player, text)
	local filteredText = game:GetService("TextService"):FilterStringAsync(text.Text, player.UserId)
	local filteredTextAsString = filteredText:GetNonChatStringForBroadcastAsync()
	
	game.Players[player].PlayerGui.Main.Background.Settings.Submit.Text = filteredTextAsString -- just for testing
	wait(3)
	game.Players[player].PlayerGui.Main.Background.Settings.Submit.Text = "Submit"
end)

What is text? You can’t pass objects through RemoteEvents, you can only fire values.

It’d be better if you used a remoteFunction here, fired the text that needs to be filtered and then returned the filtered text.

You can read more about remoteFunctions here
And you can read more about client/ server communication here

1 Like

Read the client side. It’s a textbox.

I think your issue is that you’re doing game.Players[player] when using the square brackets expects a string but you give it player, which is a Player Instance, just use the player instead, you alreayd have it, no need to try to retrieve it again.

Also why is the Server being responsible for changing UI? That’s normally the client’s job, so I’d recommend doing what @Benified4Life had mentioned and changing the code around to use a RemoteFunction, you pass in the string you want filtered, the server filters it and returns back the result of the filtering back to the client to then change text around

2 Likes

So how do I go from the client to the server then to the client?

RemoteFunctions technically already do something like that, You just Invoke the Server, the server does the filtering work, and then gives back the client the filtered string, so then the client can change the text themselves

On the game.Players[player] use game.Players[player.Name]

Could you give me that code? I don’t normally use RemoteFunctions. I understand the basics of them, though.

It would be something like this

RemoteFunction.OnServerInvoke = function(player, text)
	local filteredText = game:GetService("TextService"):FilterStringAsync(text.Text, player.UserId)
	local filteredTextAsString = filteredText:GetNonChatStringForBroadcastAsync()
	
	return filteredTextAsString
end

Where RemoteFunction is your RemoteFunction, in the client you just do InvokeServer, giving it the textbox, and then it returns the filtered text and you just use that return text to change the text of something

This is the client side, is it correct?

script.Parent.Submit.MouseButton1Click:Connect(function(player)

local text = game.ReplicatedStorage.Bio:InvokeServer(script.Parent.Bio.Text)

script.Parent.Submit.Text = text

end)

Looks good to me if you changed Bio to a RemoteFunction, make sure in the server you changed text.Text to text

It doesn’t seem to be filtering. It sets the text, though.
Client:

script.Parent.Submit.MouseButton1Click:Connect(function(player)

local text = game.ReplicatedStorage.Bio:InvokeServer(script.Parent.Bio.Text)

script.Parent.Submit.Text = text

end)

Server:

function bio(player, text)
	local filteredText = game:GetService("TextService"):FilterStringAsync(text, player.UserId)
	local filteredTextAsString = filteredText:GetNonChatStringForBroadcastAsync()

	return filteredTextAsString
end

game.ReplicatedStorage.Bio.OnServerInvoke = bio

Are you testing it from Studio or Ingame? Filtering doesn’t work from Studio

@AxeI_c That is correct as MouseButton1Click returns nothing so @OP can remove it, but it doesn’t really have any relation to what is happening here as they don’t use it anyways

You cannot get the player from MouseButton1Click. You need to use Players | Roblox Creator Documentation

Studio, does it need to be ingame?

Yes, Studio testing doesn’t do any filtering, it only filters when you test ingame

Oh, it works ingame. Thank you!

1 Like