Hey, I am currently making a squad system with a different chat channel and I am currently having issues and I am not sure how to fix it. There are currently no errors it just doesn’t work.
Squad Creation Script:
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local tcs = game:GetService("TextChatService")
local event = rs.Game.Events.RemoteEvents.squad_remote
event.OnServerEvent:Connect(function(player, target, Arg1)
if target == "CreateSquad" then
local newChannel = Instance.new("TextChannel", tcs.CustomChannels)
newChannel.Name = Arg1
local newCommand = Instance.new("TextChatCommand", tcs.CustomCommands)
newCommand.Name = Arg1
newCommand.PrimaryAlias = "/"..Arg1
local squad = Instance.new("Folder", player)
squad.Name = Arg1
local owner = Instance.new("ObjectValue", squad)
owner.Name = "Owner"
owner.Value = player
local members = Instance.new("Folder", squad)
members.Name = "Members"
elseif target == "DisbandSquad" then
local squad = player:FindFirstChild(Arg1)
if squad then
if squad.Owner.Value == player then
squad:Destroy()
elseif squad.Members:FindFirstChild(player.Name) then
squad.Members:FindFirstChild(player.Name):Destroy()
end
elseif target == "InvitePlayer" then
local squad = player:FindFirstChild(Arg1)
if squad then
if squad.Owner.Value == player then
--idk yet
end
end
elseif target == "KickPlayer" then
local squad = player:FindFirstChild(Arg1)
if squad then
if squad.Owner.Value == player then
local member = squad.Members:FindFirstChild(player.Name)
if member then
member:Destroy()
end
end
end
end
end
end)
Chat Server:
local TextChatService = game:GetService("TextChatService")
local Players = game:GetService("Players")
local rs = game:GetService("ReplicatedStorage")
local Commands = TextChatService:FindFirstChild("CustomCommands")
local Channels = TextChatService:FindFirstChild("CustomChannels")
local Remote = rs.Game.Events.RemoteEvents.chat_remote
for _, player in Players:GetPlayers() do
for _ , command in pairs(Commands:GetChildren()) do
command.Triggered:Connect(function(origin, unfiltered)
--// Makes sure the command ran has a channel related to it
if Channels:FindFirstChild(command.Name) then
if Channels[command.Name]:FindFirstChild(origin.Name) then
--// If user is in channel, remove user
Channels[command.Name][origin.Name]:Destroy()
--// Forces client to only send messages to Default Roblox Chat
Remote:FireClient(Players:FindFirstChild(origin.Name), "RBXGeneral")
else
--// If the user is not in the channel, add user
Channels[command.Name]:AddUserAsync(origin.UserId)
--// Forces client to only send messages to newly joined Channel
Remote:FireClient(game.Players:FindFirstChild(origin.Name), command.Name)
end
end
end)
end
end
Chat Client:
local TextChatService = game:GetService("TextChatService")
local rs = game:GetService("ReplicatedStorage")
local ChatBar = TextChatService:WaitForChild("ChatInputBarConfiguration")
local Remote = rs.Game.Events.RemoteEvents.chat_remote
--// Replicating server requests
Remote.OnClientEvent:Connect(function(ChannelName)
--// Forces target text channel to assigned channel
local Channel = TextChatService.CustomChannels:FindFirstChild(ChannelName) or TextChatService.TextChannels:FindFirstChild(ChannelName)
ChatBar.TargetTextChannel = Channel
--// Informs client of new channel
if ChannelName == "RBXGeneral" then
Channel:DisplaySystemMessage("You're now chatting on Default Chat.")
else
Channel:DisplaySystemMessage("You're now chatting on " .. ChannelName .. ".")
end
end)
--// Adds the Channel Tag and Color when receiving messages from Channels different than Roblox Default
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
local properties = Instance.new("TextChatMessageProperties")
if TextChatService.TextChannels:FindFirstChild(message.TextChannel.Name) then
return
end
if message.TextSource then
local player = game.Players:GetPlayerByUserId(message.TextSource.UserId)
local ChannelColor = message.TextChannel:GetAttribute("Color") or {R = 1, G = 1, B = 1}
properties.PrefixText = (string.format("<font color='rgb(%s, %s, %s)'>[%s] %s</font>",
math.round(ChannelColor.R * 255),
math.round(ChannelColor.G * 255),
math.round(ChannelColor.B * 255),
message.TextChannel.Name,
message.PrefixText
)
)
end
return properties
end
Help is appreciated.