Converting local scripts into filtering enabled friendly scripts

I were working on my own game when I realized that my script isn’t “filtering enabled friendly”. Here’s my local script.

The Script
local prefix = "-"
local debounce  = false

local Player = game.Players.LocalPlayer

Player.Chatted:connect(function(msg)
	if msg == string.lower(prefix.."help") or msg == string.lower(prefix.."h") or msg == string.lower("/e "..prefix.."help") or msg == string.lower("/e "..prefix.."h") then
		wait(.01)
		if not debounce then
		debounce = true
		script.Parent:TweenPosition(UDim2.new(0.4, 0,0.2, 0),"Out","Quad",.2)
	else
		script.Parent:TweenPosition(UDim2.new(0.4, 0,1, 0),"Out","Quad",.2)
		debounce = false
	end
end
	
	
end)

Could someone help me fixing this? Thanks!

2 Likes

I believe the chatted event is server sided.

1 Like

It works perfect without filtering enabled. :woman_shrugging:

1 Like

I believe @SteadyOn is correct. Try switching to this event: http://wiki.roblox.com/index.php?title=API:Class/Chat/Chatted

2 Likes

This is for when you use the :Chat function which causes a bubble above the player or a part.

To do this properly you’d have to implement a serverside listening event that then fires the client when the player chats (Using the Player’s .Chatted event).

3 Likes

Ah you know what, you’re right.
Sorry, I should have refrained from offering a suggestion given my lack of experience with this part of the API.

1 Like

Haha no worries, I was just looking at this a couple of days ago, hence, it is very fresh in my memory, the whole Chat and ChatService APIs seem pretty messed up and unnecessarily confusing to me.

Yea its easy to get confused because one might think its almost entirely client only but its not. Only the visual stuff is.

Take custom chats for example, you have the client send the message to the server so the server can filter it as it sends the message to everyone else including returning the filtered string back to the sender.

I have to be honest and say that the response I got is somewhat confusing as I’m not an expert in the field. Could someone try to explain it more detailed how to fix it and possibly in a way I easier can understand?

Yeah. So, what @SteadyOn suggested is this: On the server, listen to the Player.Chatted event, rather than in a LocalScript. Then, from that server-side script, fire a RemoteEvent called something like “PlayerChatted” to the client that chatted. Have the client listen to that RemoteEvent's OnClientEvent event and do your animation there.

Will it be delayed? Unfortunately yes. But I believe this is the best method besides actually editing the Chat service’s code directly.

Still I cannot fully understand it. Could you maybe give an example?

First, say you created a RemoteEvent in ReplicatedStorage and named it PlayerChatted. Then you can put this sort of code in:

On the server, add something like this:

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

Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		ReplicatedStorage.PlayerChatted:FireClient(player, msg)
	end)
end)

Then you could add this to the client:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local function onLocalPlayerChatted(msg)
	if msg == string.lower(prefix.."help") or msg == string.lower(prefix.."h") or msg == string.lower("/e "..prefix.."help") or msg == string.lower("/e "..prefix.."h") then
		wait(.01)
		if not debounce then
		debounce = true
		script.Parent:TweenPosition(UDim2.new(0.4, 0,0.2, 0),"Out","Quad",.2)
	else
		script.Parent:TweenPosition(UDim2.new(0.4, 0,1, 0),"Out","Quad",.2)
		debounce = false
	end
end

ReplicatedStorage.PlayerChatted.OnClientEvent:Connect(onLocalPlayerChatted)

By server you mean ServerScriptService correct?

Not necessarily, but yes that would qualify as being on the server.

I’ve tried to fix it and follow the instructions you gave but still not working. Could I possibly add you trough a team create or add you trough a group so you can look at it yourself?

Please DM me on here and I’ll see what will work.

1 Like