I’m trying to make a global chat but it errors on objectSuccess pcall and I don’t know how to fix it.
My script fails on the objectSuccess pcall() and results say “The sender must be connected to the same server”, my game is a singleplayer.
-- VARIABLES --
local TextChatService = game:GetService("TextChatService")
local MessagingService = game:GetService("MessagingService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TextService = game:GetService("TextService")
local Players = game:GetService("Players")
local chattedEvent = ReplicatedStorage.RemoteEvents:WaitForChild("OtherEvents").ChattedEvent
local topic = "GlobalChat"
-- SCRIPTS --
chattedEvent.OnServerEvent:Connect(function(player, message)
local dataToBeSent = player.Name..'\\'..message
MessagingService:PublishAsync(topic, dataToBeSent)
print("Published!!")
end)
MessagingService:SubscribeAsync(topic, function(message)
-- Variable
local fromPlayer, playerMessage = string.match(message.Data, "(.-)\\(.*)")
-- Script
if not table.find(Players:GetPlayers(), Players:GetPlayerByUserId(Players:GetUserIdFromNameAsync(fromPlayer))) then
for _, player in Players:GetPlayers() do
local objectSuccess, object = pcall(function()
return TextService:FilterStringAsync(
playerMessage,
Players:GetUserIdFromNameAsync(fromPlayer),
Enum.TextFilterContext.PublicChat
)
end)
if not objectSuccess then print("not object success") return end
local filterSuccess, result = pcall(function()
return object:GetChatForUserAsync(player.UserId)
end)
if not filterSuccess then print("not filter success") return end
chattedEvent:FireClient(player, fromPlayer, result)
end
end
end)
help is appreciated thanks