RemoteFunction returns string as "Instance"

Hello! I’ve been learning a bit about RemoteFunctions and Text Filtering via. TextService, and I’ve been trying to make a little system for fun where you can enter in text, and then have it filtered and displayed on the “OutputText” TextLabel beside the Textbox.

image

After finding out that using the filter functions requires them to be used on the server, I decided that a RemoteFunction would probably be handy for filtering the sent text, and then returning it back to the client. The main problem I’ve stumbled upon is that whenever I invoke the RemoteFunction with the player and text, all it returns is an “Instance” according to the output. Is there a reason for this?

image

Here’s the code below by the way:


-- Localscript inside the TextBox

local Player = game.Players.LocalPlayer

local function onFocusLost(enterPressed, inputObject)
	if enterPressed then

		local TextEntered = script.Parent.Text

		local FilteredSuccess = game.ReplicatedStorage.Events.Data.GetFilteredName:InvokeServer(Player, script.Parent.Text)

		print(FilteredSuccess)

		script.Parent.Parent.FilteredText.Text = FilteredSuccess

	else
		-- The player stopped editing without pressing Enter
		script.Parent.EditName.Text = ""
	end
end

script.Parent.FocusLost:Connect(onFocusLost)


--ServerScript, where RemoteFunction code is handled

function ReturnTextFiltered(player, text)
	
	local FilteredNameAttempt = TextService:FilterStringAsync(text, player.UserId, 1)

	local FilterSuccess = FilteredNameAttempt:GetNonChatStringForBroadcastAsync()

	return FilterSuccess
	
	--local FilteredNameAttempt = TextService:FilterStringAsync(text, player.UserId, 1)

	--local FilterSuccess
	
	--local success, fail = pcall(function()
	--	FilterSuccess = FilteredNameAttempt:GetNonChatStringForBroadcastAsync()
	--end)
	
	--if success then
	--	return FilterSuccess
	--else
	--	warn("Couldn't filter text that was sent!")
	--end	
	
end

game.ReplicatedStorage.Events.Data.GetFilteredName.OnServerInvoke = ReturnTextFiltered

Here’s also the place file.
textthingy.rbxl (29.8 KB)

I would look into the page below, that behavior is correct.


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

Try: tostring(result)

Still didn’t work unfortunately, unless this line isn’t how you do it?

script.Parent.Parent.FilteredText.Text = tostring(FilteredSuccess)

Here’s the place file if you’re interested
textthingy.rbxl (29.8 KB)

Update: Unfortunately I didn’t realize that I didn’t need to send a player object at all since it’s auto-referenced when Invoking. Thanks to everyone who helped anyway!

2 Likes