I was reading documentations and it doesn’t seem to have much about it…
@Soybeen Attributes aren’t enabled yet. At least that’s the error message I get in studio when trying to use them.
Method 1: Mute Player (Easier in my opinion)
--// Server Script in ServerScriptService
local chatService = require(game:GetService("Chat"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"); --Require our ChatService module
function mute(playerName)
chatService:GetChannel("All"):MuteSpeaker(playerName, "You're out of messages! {Early Access}"); --Grabs All channel by default, mutes speaker with reason, "You're out of messages!"
--This will still allow them to whisper to people however.
end;
function unmute(playerName)
chatService:GetChannel("All"):UnmuteSpeaker(playerName); --Unmute them
end;
mute("MrLonely1221");
unmute("MrLonely1221");
Method 2: Don’t send their messages
Easy way to “fork” the chat modules, is to go into studio, Play Solo and copy all the children of the “Chat” service in the Explorer. (Ref. 1)
When you have this, under Chat > ClientChatModules > CommandModules Make a new module with the following code:
(Also put a RemoteEvent in ReplicatedStorage named “Messages”)
-- // FileName: OutOfMessages.lua
-- // Written by: MrLonely1221
-- // Description: Stop users from sending messages when they are out.
local util = require(script.Parent:WaitForChild("Util"));
local runService = game:GetService("RunService");
local hasMessages = true;
local chatLocalization = nil;
pcall(function() chatLocalization = require(game:GetService("Chat").ClientChatModules.ChatLocalization); end);
if chatLocalization == nil then chatLocalization = {}; function chatLocalization:Get(key,default) return default; end; end;
game:GetService("ReplicatedStorage"):WaitForChild("Messages").OnClientEvent:Connect(function(canMessage)
hasMessages = canMessage; --Set our local variable to be true or false, depending on what we get from the client.
end);
function ProcessMessage(message, ChatWindow, ChatSettings)
if hasMessages then return false; end; --If they have messages, return false (not a command) send their message.
local channelObj = ChatWindow:GetCurrentChannel(); --Get currently open channel
if channelObj then
util:SendSystemMessageToSelf(
chatLocalization:Get("GameChat_OutOfMessages_Message","You are out of messages! {Early Access}"),
channelObj,
{}
); --Send error message
end;
return true; --Returning true in the ProcessMessage function will stop the message from sending
end;
return {
[util.KEY_COMMAND_PROCESSOR_TYPE] = util.COMPLETED_MESSAGE_PROCESSOR; --Value = 1; Process when they try to send it
[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage; --Our function above to send them a message saying they're out
};
To stop them from sending messages, simply fire the remote event from a server script with true or false, depending on if they can or can’t send a message.
local player = game:GetService("Players"):FindFirstChild("MrLonely1221");
game:GetService("ReplicatedStorage"):FindFirstChild("Messages"):FireClient(player, false) --Guess I'm out of messages, Send true instead of false to allow them to send messages again
Reference 1
I hope this was a good enough explanation.
I’m kind of confused here, nothing is happening when using your way. The 2nd Method.
You made a ModuleScript in ClientChatModules > CommandModules.
The RemoteEvent named “Messages” in ReplicatedStorage.
And the ServerScript firing the event in ServerScriptService?
Sorry, I had a typo in my original code and forgot to add the > CommandModules
Ah, yea that was the issue.
It works now…
Is there a way to delete the error message after 5 seconds or something?
Sadly that message stays there in their chat.
I’m trying to find a method to remove it, but the only thing there is :Clear() which would clear all messages from chat.
Okay, I lied in my last post. This is a little messy and hacky, and if someone knows a better way, please let me know.
Replace the module I sent before with this one. It will go ahead and delete the message after 5 seconds. (ngl, really proud of myself for getting this. Took my half an hour. I should have been asleep an hour ago.)
-- // FileName: OutOfMessages.lua
-- // Written by: MrLonely1221
-- // Description: Stop users from sending messages when they are out.
local util = require(script.Parent:WaitForChild("Util"));
local runService = game:GetService("RunService");
local hasMessages = true;
local messageToShow = "You are out of messages! {Early Access}";
local messageLogDisplay = require(game:GetService("Players").LocalPlayer:WaitForChild("PlayerScripts"):WaitForChild("ChatScript"):WaitForChild("ChatMain"):WaitForChild("MessageLogDisplay"));
local chatLocalization = nil;
pcall(function() chatLocalization = require(game:GetService("Chat").ClientChatModules.ChatLocalization); end);
if chatLocalization == nil then chatLocalization = {}; function chatLocalization:Get(key,default) return default; end; end;
game:GetService("ReplicatedStorage"):WaitForChild("Messages").OnClientEvent:Connect(function(canMessage)
hasMessages = canMessage; --Set our local variable to be true or false, depending on what we get from the client.
end);
function ProcessMessage(message, ChatWindow, ChatSettings)
if hasMessages then return false; end; --If they have messages, return false (not a command) send their message.
local channelObj = ChatWindow:GetCurrentChannel(); --Get currently open channel
if channelObj then
util:SendSystemMessageToSelf(
chatLocalization:Get("GameChat_OutOfMessages_Message",messageToShow),
channelObj,
{}
); --Send error message
end;
coroutine.wrap(function()
wait(5);
for index, obj in pairs(ChatWindow.MessageLogDisplay.MessageObjectLog) do
table.foreach(obj, print)
if obj.BaseMessage.Text == messageToShow then
obj:Destroy();
end;
end;
end)();
return true; --Returning true in the ProcessMessage function will stop the message from sending
end;
return {
[util.KEY_COMMAND_PROCESSOR_TYPE] = util.COMPLETED_MESSAGE_PROCESSOR; --Value = 1; Process when they try to send it
[util.KEY_PROCESSOR_FUNCTION] = ProcessMessage; --Our function above to send them a message saying they're out
};
Tysm! I really appreciate your help.
No problem! Always gotta help people trying to script.