Join and Leave System Messages

Hello DevForum!

I want to make a join and leave message script into chat. I was able to make one.

The problem is, though, I made a separate System Channel in the chat, but the join and leave messages will only appear in the “All” Channel. I can’t find a way to fix this.

Here is my local script (placed in StarterPlayerScripts):

-- Variables defined for the Roblox Services
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui")

-- Variables defined for the RemoteEvents
local PlayerJoinedEvent = ReplicatedStorage.PlayerJoinedEvent
local PlayerLeftEvent = ReplicatedStorage.PlayerLeftEvent

-- Variable for the Player's Display Name
local DisplayName = player.DisplayName

local function OnPlayerJoined(player)
	StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "{System}: "..DisplayName.." ("..player..") has joined the game.", -- This is the join message. Feel free to edit it to your liking
		Color = Color3.new(1, 1, 1), -- The color of the Join Message. Feel free to edit it to your liking.
        Font = Enum.Font.SourceSans, -- This is the font for the Join Message. Feel free to edit it to your liking.
        FontSize = 16 -- This is the FontSize of the Join Message. Feel free to edit it to your liking.
	})
end

local function OnPlayerLeft(player)
	StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "{System}: "..DisplayName.." ("..player..") has left the game.", -- This is the leave message. Feel free to edit it to your liking
		Color = Color3.new(1, 1, 1), -- The Color of the leave message. Feel free to edit it to your liking.
        Font = Enum.Font.SourceSans, -- This is the font for the leave message. Feel free to edit it to your liking.
        FontSize = 16 -- This is the FontSize of the leave message. Feel free to edit it to your liking.
	})
end

-- Declares the local functions in the script
PlayerJoinedEvent.OnClientEvent:Connect(OnPlayerJoined)
PlayerLeftEvent.OnClientEvent:Connect(OnPlayerLeft)

Here is my script that I placed in ServerScriptService:

-- Variables Defined for the Roblox Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

-- Variables for the RemoteEvents added earlier
local PlayerJoinedEvent = ReplicatedStorage.PlayerJoinedEvent
local PlayerLeftEvent = ReplicatedStorage.PlayerLeftEvent


local function OnPlayerAdded(Player)
	 PlayerJoinedEvent:FireAllClients(Player.Name)
end

local function OnPlayerRemoving(Player)
	PlayerLeftEvent:FireAllClients(Player.Name)
end

-- Declares the local functions in the script
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)

Can someone help me solve this problem?

You dont need 500 lines to make a join and leave message. Heres a place file that has all u need. Feel free to use the scripts and stuff in ur game

Join msg and leave msg.rbxl (33.0 KB)

proof it works:

image

I know how to put a join and leave message in the chat.

I want to know how to put Join and Leave messages in different Channels in the Chat.

I said it in my post.

I see. It’s semi-complex? I can provide a base code sample for you and documentation.

Documentation 1: DevHub
Documentation 2: DevForum

Note: This’d have to be on the server, if that’s okay with you.

local serverScriptService = game:GetService("ServerScriptService")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local name = "System"

local speaker = chatServiceModule:GetSpeaker(name)
if not speaker then
	speaker = chatServiceModule:AddSpeaker(name)
	speaker:SetExtraData("NameColor",Color3.fromRGB(100,100,100))
end

local send = function(message,channel)
	if not speaker:IsInChannel(channel) then
		speaker:JoinChannel(channel)
	end
	speaker:SayMessage(message,channel)
end

send("hi","all") --> How to send a message with it, connect it to the join and leave and you're good to go!

Is this what you were looking for? You can customize the channel, I just used ‘all’ as an example. You can also use the method below with ‘SendSystemMessage’, this one just allows you to set the system’s name and chat color.

3 Likes

For quick general message use:
https://developer.roblox.com/en-us/api-reference/function/StarterGui/SetCore

For Channel specific messages you can refer to

where you will find ChatService which contains

GetChannel

    Parameters: string channelName
    Description: Returns the channel with the given name, or nil if it does not exist.
    Returns: ChatChannel

Then you can use the chatchannel to make a system message for that channel

SendSystemMessage

    Parameters: string message
    Description: Sends a message from the “System” ChatSpeaker{ChatSpeaker] to the channel.
    Returns: void
2 Likes

Is this what you mean?


local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)

local function playerAdded(player)
    local allChannel = ChatService:GetChannel("All")
    allChannel:SendSystemMessage("{System} " .. player.Name .. " joined the game.")
end

Players.PlayerAdded:Connect(playerAdded)
for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end

yes, that’ll work for all channels

Let me see if it works.

I put this as a local script in StarterPlayerScripts right?

Try this script.
Make a RemoteEvent in Replicated Storage.

local playerjoined = game.ReplicatedStorage.JoinLeaveEvent.PlayerJoined
local playerleft = game.ReplicatedStorage.JoinLeaveEvent.PlayerLeft

playerjoined.OnClientEvent:Connect(function(player)
	game.StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = player.." has join the game",
		Color = Color3.fromRGB(0, 12, 255),
		FontSize = Enum.FontSize.Size32,
		Font = Enum.Font.SourceSansBold
	})
end)

playerleft.OnClientEvent:Connect(function(player)
	game.StarterGui:SetCore("ChatMakeSystemMessage",{
		Text = player.." has left the game",
		Color = Color3.fromRGB(255, 0, 0),
		FontSize = Enum.FontSize.Size32,
		Font = Enum.Font.SourceSansBold
	})
end)

Thats my original script, but slightly edited.

It didn’t send a message to any of the channels.

It’ll need to be a server script, if that’s okay with you. There’s probably a way to make client-side messages without ‘:SetCore’ but it’d probably be more hacky.

The default chat system’s source is in ServerScriptService which is not replicated to the client, unfortunately.

Ohhhh. So this script:


local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)

local function playerAdded(player)
    local allChannel = ChatService:GetChannel("All")
    allChannel:SendSystemMessage("{System} " .. player.Name .. " joined the game.")
end

Players.PlayerAdded:Connect(playerAdded)
for _, player in ipairs(Players:GetPlayers()) do
    playerAdded(player)
end

needs to be a regular one instead of a local one and placed into ServerScriptService?

Yes, try it out and let me know if it works.

It worked! Thanks a lot for the help mate.

1 Like