Hello! I am making a cross chatting game, I tried using a dictionary, told me it’s unable to publish that, I tried to index it, failed to work, tried searching for the problem for 10 minutes, didn’t work.
ERROR:
Cannot publish Array, can only accept valid UTF-8 characters.
SubscribeAsync code:
local MS = game:GetService("MessagingService")
task.wait()
MS:SubscribeAsync("ChatEvent", function(msg)
local decoded = msg.Data
if typeof(decoded[1]) == "string" and typeof(decoded[2]) == "Instance" and decoded[2].ClassName == "Player" then
if script:FindFirstChild("ChatFrame") then
local content = script:FindFirstChild("ChatFrame"):Clone()
local success, result = pcall(function()
local c, isr = game.Players:GetUserThumbnailAsync(decoded[2].UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size60x60)
if isr then
return c
else
return "error"
end
end)
if success then
if result then
if result ~= "error" then
pcall(function()
content.AuthorPic.Image = result
content.Author.Text = decoded[2].Name
end)
local s, r = pcall(function()
local filtered = game:GetService("Chat"):FilterStringForBroadcast(tostring(decoded[1], decoded[2]))
if typeof(filtered) == "string" then
return filtered
end
end)
if s then
pcall(function()
content.Chat.Text = r
end)
end
end
for i,v in pairs(game.Players:GetDescendants()) do
if v.ClassName == "ScrollingFrame" and v.Parent.Name == "ChatHolder" and v.Parent.ClassName == "Frame" and v.Parent.Parent.Name == "PrimaryChat" then
content.Name = decoded[2].Name
content.Parent = v
end
end
end
end
end
end
end)
Publish code:
local ratelimit = 0
script.Parent.OnServerEvent:Connect(function(plr, msg)
if typeof(msg) == "string" and (typeof(plr) == "Instance" and plr ~= nil) then
local txt = script.Parent.Parent
ratelimit += 1
if ratelimit >= 10 then
txt.TextEditable = false
txt.PlaceholderColor3 = Color3.fromRGB(255, 85, 0)
txt.PlaceholderText = "You are being rate limited."
task.wait(4)
txt.TextEditable = true
txt.PlaceholderColor3 = Color3.fromRGB(178, 178, 178)
txt.PlaceholderText = "Chat..."
else
local success, result = pcall(function()
game:GetService("MessagingService"):PublishAsync("ChatEvent", {[1] = tostring(msg), [2] = plr})
txt.Text = ""
end)
if not success then
if typeof(txt) == "Instance" and txt.ClassName == "TextBox" then
txt.TextEditable = false
txt.PlaceholderColor3 = Color3.fromRGB(255, 255, 0)
txt.Text = ""
txt.PlaceholderText = "ERROR! CHECK DEV CONSOLE FOR MORE INFO"
warn([[
===== ERROR =====
TYPE: MESSAGE SEND FAIL
EXECUTED: ]] .. os.time() .. [[
PROCESS ERROR: PUBLISHASYNC FAILED
ERROR:
--
]] .. result .. [[
--
ALERT DEVLEOPERS OR UPPER ABOUT THIS ISSUE.
]])
task.wait(4)
txt.TextEditable = true
txt.PlaceholderColor3 = Color3.fromRGB(178, 178, 178)
txt.PlaceholderText = "Chat..."
end
end
end
end
end)
local ratedecrease = coroutine.wrap(function()
while task.wait(1) do
if ratelimit ~= 0 then
ratelimit = ratelimit - 1
task.wait(2)
end
end
end)
ratedecrease()
