I want to make a combat log channel only for a local player. Kind of like when they kill a mob theres a dedicated chat log for that. Unfortuantely I dont know how to add players to the chat so that only they can see it.
I technically I can have unique channel names like Combat_{player.UserID} and add each player to them so only that player can see it. But then the name shows Combat1923823 rather than Combat which isnt feasible. Is there a way to do this specifically?
The following code works but shows up as:
local Players = game.Players
local TextChannelService = game.TextChatService
local textChannels = TextChannelService:WaitForChild("TextChannels")
local globalChannel = Instance.new("TextChannel")
globalChannel.Name = "Global"
globalChannel.Parent = textChannels
local combatLog ={}
Players.PlayerAdded:Connect(function(player: Player)
globalChannel:AddUserAsync(player.UserId)
if not combatLog[player.UserId] then
local combatChannel = Instance.new("TextChannel")
combatChannel.Name = "Combat" .. player.UserId
combatChannel:AddUserAsync(player.UserId)
combatChannel.Parent = textChannels
end
end)
The code will work but then you have many combat with user id channels
But? The code will make it so only the player you add to the channel will see the channel so idk what you’re looking for… Are you saying you want a unique identifier without putting it in the channel name?
Yea I wanted a unique id without it being in the channel name, But then I realized… I could just use an event message and filter off that.
So its pretty simple. Heres a solution. Feel free to provide other suggestions
Working code:
--server
local Players = game.Players
local TextChannelService = game.TextChatService
local CombatMessage:RemoteEvent = Instance.new("RemoteEvent", game.ReplicatedStorage)
CombatMessage.Name = "CombatMessage"
local ChannelTabsConfiguration = TextChannelService:WaitForChild("ChannelTabsConfiguration")
local textChannels = TextChannelService:WaitForChild("TextChannels")
ChannelTabsConfiguration.Enabled = true
local globalChannel = Instance.new("TextChannel")
globalChannel.Name = "Global"
globalChannel.Parent = textChannels
local combatChannel = Instance.new("TextChannel")
combatChannel.Name = "Combat"
combatChannel.Parent = textChannels
Players.PlayerAdded:Connect(function(player: Player)
globalChannel:AddUserAsync(player.UserId)
combatChannel:AddUserAsync(player.UserId)
end)
-- some example loop
while(true) do
task.wait(5)
local players = Players:GetPlayers()
local randomPlayer = players[math.random(1, #players)]
CombatMessage:FireClient(randomPlayer, tick().. " Gained 10 Exp from Enemy")
end
Client:
local Player = game.Players.LocalPlayer
local TextChatService = game:GetService("TextChatService")
local combatChannel = TextChatService:WaitForChild("TextChannels"):WaitForChild("Combat")
local CombatMessage: RemoteEvent = game.ReplicatedStorage:WaitForChild("CombatMessage")
CombatMessage.OnClientEvent:Connect(function(message: string)
combatChannel:DisplaySystemMessage(string.format("<font color='#949494'>[COMBAT]</font>: <font color='#949494'>%s</font>", message))
end)
Ah thanks for the feedback! Could you explain why not to do this? I typically use third party Networking modules so Im not familiar on best practices with the remote events.