I’m trying to make a chat commands script that allows the player to say another word if they use the command “/word”. In this case, when the player says “/word”, I
am wanting it to say “DRONESYSTEMS” and then hide the “/word” from the chat.
When I type “/word” in the chat, it successfully outputs “DRONESYSTEMS”, however, it does not hide “/word”.
Serverscript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("ChatCMDS")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msgs)
if msgs:lower() == "/word" then
RemoteEvent:FireClient(plr,msgs) -- Send the message to the client
end
end)
end)
Localscript
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("ChatCMDS")
local Chatting = false -- Variable to track if the player is currently chatting
local function Chat(msg)
if game.ReplicatedStorage:FindFirstChild('DefaultChatSystemChatEvents') then
game.ReplicatedStorage.DefaultChatSystemChatEvents.SayMessageRequest:FireServer(msg, "All")
else
game:GetService("TextChatService").TextChannels.RBXGeneral:SendAsync(msg)
end
end
RemoteEvent.OnClientEvent:Connect(function(msg)
if not Chatting then -- Check if the player is not currently chatting
Chatting = true -- Set Chatting to true to prevent the player from chatting again
Chat("DRONESYSTEMS") -- Use the message passed by the server
wait(1) -- Wait for 1 second before allowing the player to chat again
Chatting = false -- Set Chatting to false to allow the player to chat again
end
end)
Let me know if more info is needed, thank you!