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

[Custom Chat] How to add FilterStringAsync?

Okay, so im trying to use a Custom Chat i found.. (Ofcourse im going to edit it..) But first im trying to make it works with FilterStringAsync.. But when i try it it gives errors and stuff ;-; tried to look up a custom chat with FilterStringAsync but couldnt really find one :/

Please help me with this

local chats = script.Parent.Chats
local last

function newChat(msg,plr)
	if #msg > 0 then
		for i, c in pairs(chats:GetChildren()) do
			c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
		end
		local newMessage = script.Message:clone()
		if #chats:GetChildren() == 10 then
			chats:GetChildren()[1]:Destroy()
		end
		
		if plr.Name == "" then
		newMessage.TextColor3 = script.Owner.Value
		newMessage.Text = "[OWNER] " .. plr.Name ..": ".. msg
		
		elseif plr.Name == "" or plr.Name == "" or plr.Name == "" then
		newMessage.TextColor3 = script.Admin.Value
		newMessage.Text = "[ADMIN] " .. plr.Name ..": ".. msg
		
		elseif game:GetService("GamePassService"):PlayerHasPass(plr, 0)then
		newMessage.TextColor3 = script.VIP.Value
		newMessage.Text = "[VIP]" .. plr.Name ..": ".. msg
		
		else 
		newMessage.Text = plr.Name ..": ".. msg
		end
	    
	    newMessage.Position = UDim2.new(0, 0, 0.9, 0)
		newMessage.Parent = chats
		last = newMessage
	end
end

function join(plr)
	for i, c in pairs(chats:GetChildren()) do
			c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
		end
		local newMessage = script.Message:clone()
		if #chats:GetChildren() == 10 then
			chats:GetChildren()[1]:Destroy()
		end	
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " joined the server!"
        newMessage.TextColor3 = script.CONSOLE.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
		newMessage.Parent = chats
		last = newMessage
end

function left(plr)
	for i, c in pairs(chats:GetChildren()) do
			c.Position = c.Position - UDim2.new(0, 0, 0.1, 0)
		end
		local newMessage = script.Message:clone()
		if #chats:GetChildren() == 10 then
			chats:GetChildren()[1]:Destroy()
		end	
        newMessage.Text = "[CONSOLE] " .. plr.Name .. " left the server."
        newMessage.TextColor3 = script.CONSOLE.Value
        newMessage.Position = UDim2.new(0, 0, 0.9, 0)
		newMessage.Parent = chats
		last = newMessage
end

game.Players.PlayerAdded:connect(function(plr)
	join(plr)
end)

game.Players.PlayerRemoving:connect(function(plr)
	left(plr)
end)

game.Players.PlayerAdded:connect(function(plr)
	plr.Chatted:connect(function(msg)
		newChat(msg, plr)
	end)
end)

for i, player in pairs(game.Players:GetPlayers()) do
	player.Chatted:connect(function(msg)
		newChat(msg, player)
	end)
end

4 comments

0

The message is being created via the function 'newChat', so it would be best to filter the string there using FilterStringBroadcast, here is a pretty neat tutorial: https://www.youtube.com/watch?v=Ph1nCEIlZ2c

0

the problem is that if i try to add :FilterStringForBroadcast or :FilterStringAsync to the function it says "Unknown Global: 'newChat'"

0

I heard FilterStringAsync is deprecated, I agree with YabaDabaD0O

0

Watch the language! Profanity is not allowed on the website. https://scriptinghelpers.org/help/community-guidelines

1 answer

✓ Accepted answer

Try adding this the newChat function, but as a side note, FilterStringForBroadcast only works on Servers

local chatservice = game:GetService("Chat")
local newmessage = chatservice:FilterStringForBroadcast(msg, plr)

Then change msg to newmessage OR You can wait until the message is filtered, since the custom chat your using is using the Chatted event. So you could add:

wait(.1)

Or any other number you want.

1 comment

0

If your filtering it manually, then you need pcall: http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions#pcall

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