I am currently making an in-game chatlog and it all works yet when a player types a message it is printed/cloned twice.
Local script:
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local tcs = game:GetService("TextChatService")
local event = rs.Events.chatEvent
local ui_service = require(rs.Modules.UI_Service)
local ui = script.Parent
local Frame = ui:WaitForChild("ChatFrame")
local ScrollingFrame = Frame:WaitForChild("ScrollingFrame")
local template = ScrollingFrame:WaitForChild("Template")
local AdminFrame = ui:WaitForChild("AdminFrame")
local AdminScrollingFrame = AdminFrame:WaitForChild("ScrollingFrame")
local Admintemplate = ScrollingFrame:WaitForChild("Template")
local mouse = game.Players.LocalPlayer:GetMouse()
event.OnClientEvent:Connect(function(msg, chatType)
if chatType == "CHATLOG" then
ui_service.makeResizable(Frame, 30, 0.5, mouse, script.Parent.resizer)
ui_service.makeDraggable(Frame)
tcs.OnIncomingMessage = function(TextChatMessage)
if TextChatMessage.Text then
local templateClone = template:Clone()
local player = Players:GetPlayerByUserId(TextChatMessage.TextSource.UserId)
templateClone.Parent = ScrollingFrame
templateClone.Text = player.Name..": ".. TextChatMessage.Text
end
end
end
end)
To prevent it from doubling you should add a debounce to your code. So wherever the you have the code that sends the message from the client to the server, you should add a quick debounce to the event.
I’ve noticed that a few people have had this issue with radio systems and the such in the past when using Roblox’s Chatted event, and the simplest solutions were to just add a debounce.
local debounce = false
if not debounce then
debounce = true
Event:FireServer(arguments)
task.wait(0.1)
debounce = false
end
local rs = game:GetService("ReplicatedStorage")
local sss = game:GetService("ServerScriptService")
local event = rs.Events.chatEvent
local commands = rs.Commands
local prefix = "/"
local debounce = false
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if not debounce then
debounce = true
event:FireClient(player, msg, "CHATLOG")
task.wait(0.1)
debounce = false
end
end)
end)
Remember to check if the TextChatMessage’s status is Success:
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local tcs = game:GetService("TextChatService")
local event = rs.Events.chatEvent
local ui_service = require(rs.Modules.UI_Service)
local ui = script.Parent
local Frame = ui:WaitForChild("ChatFrame")
local ScrollingFrame = Frame:WaitForChild("ScrollingFrame")
local template = ScrollingFrame:WaitForChild("Template")
local AdminFrame = ui:WaitForChild("AdminFrame")
local AdminScrollingFrame = AdminFrame:WaitForChild("ScrollingFrame")
local Admintemplate = ScrollingFrame:WaitForChild("Template")
local mouse = game.Players.LocalPlayer:GetMouse()
event.OnClientEvent:Connect(function(msg, chatType)
if chatType == "CHATLOG" then
ui_service.makeResizable(Frame, 30, 0.5, mouse, script.Parent.resizer)
ui_service.makeDraggable(Frame)
tcs.OnIncomingMessage = function(TextChatMessage)
if TextChatMessage.Status == Enum.TextChatMessageStatus.Success and TextChatMessage.Text then
local templateClone = template:Clone()
local player = Players:GetPlayerByUserId(TextChatMessage.TextSource.UserId)
templateClone.Parent = ScrollingFrame
templateClone.Text = player.Name..": ".. TextChatMessage.Text
end
end
end
end)