Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why isnt FilterStringAsync Working? [Solved]

EDIT: I fixed it as you didn't need to send a player variable when firing a remote event to a server script.

My custom chat gui isn't working. The game is filtering enabled and its always giving this error:

11:07:47.311 - ServerScriptService.ServerChatHandler:9: attempt to concatenate local 'message' (a userdata value)

Local Script:

-- Scripted by LifeInDevelopment
local userInputService = game:GetService('UserInputService')
local replicatedStorage = game:GetService('ReplicatedStorage')

local chatEvent = replicatedStorage:WaitForChild('ChatEvent')
local sendChatMessage = replicatedStorage:WaitForChild('SendChatMessage')

local player = game.Players.LocalPlayer

local gui = script.Parent
local chatFrame = gui:WaitForChild('ChatFrame')
local woodBackground = chatFrame:WaitForChild('WoodBackground')
local chatLabels = chatFrame:WaitForChild('ChatLabels')
local chatBox = gui:WaitForChild('ChatBox')

local chat1 = chatLabels:WaitForChild('Chat1')
local chat2 = chatLabels:WaitForChild('Chat2')
local chat3 = chatLabels:WaitForChild('Chat3')
local chat4 = chatLabels:WaitForChild('Chat4')
local chat5 = chatLabels:WaitForChild('Chat5')
local chat6 = chatLabels:WaitForChild('Chat6')
local chat7 = chatLabels:WaitForChild('Chat7')
local chat8 = chatLabels:WaitForChild('Chat8')


local chat = {chat1, chat2, chat3, chat4, chat5, chat6, chat7, chat8}
local maxMessages = 8

chatBox.FocusLost:connect(function(enterPressed)
	if enterPressed then
		chatEvent:FireServer(player, chatBox.Text)
		addMessage('[' .. player.Name .. ']: ' .. chatBox.Text)
		chatBox.Text = "Press '/' to chat"
	end
end)

userInputService.InputBegan:connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.Slash then
		chatBox:CaptureFocus()
	end
end)

sendChatMessage.OnClientEvent:connect(function(filteredString, sender)
	print(filteredString)
	addMessage('[' .. sender.Name .. ']: ' .. filteredString)
end)

function addMessage(filteredString)
	chat1.Text = chat2.Text
	chat2.Text = chat3.Text	
	chat3.Text = chat4.Text
	chat4.Text = chat5.Text
	chat5.Text = chat6.Text
	chat6.Text = chat7.Text
	chat7.Text = chat8.Text
	chat8.Text = filteredString
end

Server Script:

local replicatedStorage = game:GetService('ReplicatedStorage')

local chatEvent = replicatedStorage:WaitForChild('ChatEvent')
local sendChatMessage = replicatedStorage:WaitForChild('SendChatMessage')

chatEvent.OnServerEvent:connect(function(player, message)
	for _, v in pairs (game.Players:GetPlayers()) do
		local filteredString = '[' .. player.Name .. ']: ' .. message
		if not game:GetService('RunService'):IsStudio() then
			print('Not in studio, can filter string')
			local filteredString = '[' .. player.Name .. ']: ' .. game.Chat:FilterStringAsync(message, player, v)
		end
		sendChatMessage:FireClient(v, filteredString)
	end
end)

1 comment

0

That used to mess me up too.

1 answer

The error already tells you what you need to fix. And looking at your code, you put the arguments of the function as (player, message) and the arguments of the FilterStringAsync as (message, player, v), which makes the FilterStringAsync think that the "player" in your function is the "message" in the FilterStringAsync. Basically, you messed up on the arguments.

Thus, to fix it just change the

game.Chat:FilterStringAsync(message, player, v)

to

game.Chat:FilterStringAsync(player, message, v)

3 comments

0

It didn't work, tested it in play solo and in game and it didn't work.

0

did it return any errors?

0

In play solo it returned the same error, in play mode it didn't do anything, not even send the message to everyone else.

This discussion is preserved as it was. New answers, comments, and votes are closed.