Making a Chat Speaker Private-Message a player

I have this thing that adds a “Speaker” to the game (called “System”) through the Chat service, and it can post things in chat using :SayMessage(). That part works just fine. However, how would I make it PM a single player instead of the “All” channel? Is it even possible?

SSS = game:GetService("ServerScriptService")
ChatServ = require(SSS:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
if not ChatServ:GetChannel("All") then
    while true do
        local ChannelName = ChatServ.ChannelAdded:Wait()
        if ChannelName == "All" then 
            break
        end
    end
end
local System = ChatServ:AddSpeaker("System")
System:JoinChannel("All")
System:SetExtraData("NameColor", Color3.fromRGB(255, 0, 0))
System:SetExtraData("ChatColor", Color3.fromRGB(255, 0, 0))
System:SayMessage("test", "All")
2 Likes

The PrivateMessaging module (used in the /w command) will create a different ChatChannel with only the two users who are chatting. You can look more into this at the game.CoreGui.RobloxGui.Modules.Server.ServerChat.DefaultChatModules.PrivateMessaging module. Alternatively, you can just get the ChatSpeaker of the player you want to send a message to, and use the :SendSystemMessage method on the ChatSpeaker to create a message that will only show for them.

I’m having trouble getting the chat speaker of a given player. Do you know how I would go about doing that?
EDIT: And to follow up, how might I get the player that owns a speaker after I use the SpeakerAdded event? Would it be the speaker’s name?

You can make the Core Gui Object visible inside the explorer by enabling an option inside the Roblox Studio Settings As shown below.Screenshot_17

That seems interesting, but it doesn’t seem to help me much. Where were you going with this?

To get the chat speaker of a player do ChatService:GetSpeaker(plr.Name)
To get the player of a chat speaker do ChatSpeaker:GetPlayer() (returns nil if the chat speaker is a bot)

1 Like

Alright, so assuming I know the two speakers (System and the player speaker) would I do something like this?

PlayerSpeaker:SendSystemMessage(message, System)

Not really, SendSystemMessage takes 3 arguments: the message, the channel name, and any ExtraData for the message. It would be more like

PlayerSpeaker:SendMessage(message,"All",{ChatColor = Color3.new(1,0,0)}) 

I think the ExtraData argument is optional though. If you aren’t using the “System” speaker for anything else except sending private messages, there’s really no use for it.
(Edit: You could also set the channel to “System” so that the message appears with {System} before it, like how the friend join notification works)

7 Likes

Oh my god, finally! It works! Thank you so much. This is exactly what I needed!

1 Like