How to Make a Join and Leave Message v3

This tutorial was entirely rewritten from scratch from the suggestions I received in the replies below. I hope all of you find it more convienient.

This tutorial assumes you know the basics of scripting.

As many of you know, Roblox only provides a message for when one of your friend joins your experience by default. This resource will explain how you can make a Player Join and Leave message for every single person who joins a server in your experience.

This tutorial will be divided into 2 sections.

Section One will be Join and Leave Messages that will take place in the Chat Channel where everyone chats in.

Section Two will be Join and Leave Messages that will take place in an entirely different Chat Channel for convenience.

I would recommend Part One for Beginning Scripters and Part Two for more experienced scripters.

Section 1 (For Beginners)

Let me give sort of a background first.

Some actions in scripts can only be performed by a server and other actions only by a client. For example, a player (client) may activate a GUI button, upon which the server needs to enact a game-wide change. In these cases we’ll need a RemoteEvent or RemoteFunction.

A RemoteEvent is designed to provide a one-way message between the server and clients, allowing Scripts to call code in LocalScripts and vice-versa. This message can be directed from one client to the server, from the server to a particular client, or from the server to all clients.

Now that you understand what RemoteEvents are we can start scripting.

First, you’re going to have to put a RemoteEvent inside ReplicatedStorage for this Section of the tutorial.

Insert a RemoteEvent into ReplicatedStorage.

You can name the RemoteEvent whatever you want, but for the convenience of this tutorial, you can name it PlayerEvent

Next, you need to insert a script into ServerScriptService. The name of this script doesn’t matter.

Inside the script you’ll want to define the variables for the services you want to use for the Join and Leave Message.

-- Variables Defined for the Services used in the script
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Since the RemoteEvent we added earlier is in Replicated Storage, we're going to need to use ReplicatedStorage in the script.
local Players = game:GetService("Players") -- This Tutorial is about **Players** Joining and Leaving your game Right?

We’ll also need to make variables for the RemoteEvent we inserted in ReplicatedStorage earlier:

local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Since the RemoteEvent we added earlier is in Replicated Storage, we're going to need to use ReplicatedStorage in the script.
local Players = game:GetService("Players") -- This Tutorial is about **Players** Joining and Leaving your game Right?

local PlayerEvent = ReplicatedStorage.PlayerEvent -- Variable defined for the RemoteEvent we added earlier.

Next, we’ll need to activate or “Fire” the RemoteEvent when the player joins and leaves the server.

-- Fire the Event when the Player Joins
Players.PlayerAdded:Connect(function(Player)
       PlayerEvent:FireAllClients(Player.Name, "OnPlayerJoined")
end

-- Fire the Event when the Player Leaves
Players.PlayerAdded:Connect(function(Player)
      PlayerEvent:FireAllClients(Player.Name, "OnPlayerLeave")
end

-- We fire the event with the arguments Player.Name because we want the player's name to appear in the chat with the Join and Leave Message.

The End Result of the First Script should look like this:

-- Variables Defined for the Services used in the script
local ReplicatedStorage = game:GetService("ReplicatedStorage") -- Since the RemoteEvent we added earlier is in Replicated Storage, we're going to need to use ReplicatedStorage in the script.
local Players = game:GetService("Players") -- This Tutorial is about **Players** Joining and Leaving your game Right?

-- Variables for the RemoteEvents added earlier
local PlayerEvent = ReplicatedStorage.PlayerEvent

-- Fire the Event when the Player Joins
Players.PlayerAdded:Connect(function(Player)
       PlayerEvent:FireAllClients(Player.Name, "OnPlayerJoined")
end

-- Fire the Event when the Player Leaves
Players.PlayerRemoving:Connect(function(Player)
      PlayerEvent:FireAllClients(Player.Name, "OnPlayerLeft")
end

Now we’ll need to make a local script that will make the messages appear when a player joins and leaves in the chat.

Insert a Local Script in StarterPlayerScripts. StarterPlayerScripts is located in the StarterPlayer Folder in Roblox Studio’s Explorer.

Type in the following code into the Local Script you just created:

-- Once again defining variables for all the Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui") -- We're going to use the StarterGui in this script since the Chat Messages are a part of the StarterGui.
local Players = game:GetService("Players")

-- Defining the variable for the RemoteEvent again
local PlayerEvent = ReplicatedStorage.PlayerEvent

Now we will be creating the Join and Leave messages.
The join and leave messages are customizable by Message Color, Font, Font Size, and the Join and Leave Message Text.

PlayerEvent.OnClientEvent:Connect(function(player, state)
if state ==  "OnPlayerJoined" then
-- The message below will appear in the Chat when a Player Joins. The message is completely customizable by Font, Text Color, and Text Size!
              StarterGui:SetCore("ChatMakeSystemMessage", {
		        Text = "{System}: "..player.." has joined the game.",
	         	Color = Color3.new(1, 1, 1)
	     })

            elseif state == "OnPlayerLeft" then
              StarterGui:SetCore("ChatMakeSystemMessage", {
-- The message below will appear in the Chat when a Player Leaves. The message is completely customizable by Font, Text Color, and Text Size!
		                 Text = "{System}: "..player.." has left the game.",
		                 Color = Color3.new(1, 1, 1)
	                    })

            end 
end

You may have noticed that the other argument when we fired the Remote Event in the first script was “OnPlayerJoined” and “OnPlayerLeft”.

When the RemoteEvent fires for when a Player Joins, the player’s “state” was considered “OnPlayerJoined” thus creating the Join Message.

Its the same concept for when a player leaves.

When the RemoteEvent fires for when a Player Leaves, the player’s “state” was considered “OnPlayerLeft” thus creating the Leave Message.

The final result of the local script should be this:

-- Once again defining variables for all the Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local StarterGui = game:GetService("StarterGui") -- We're going to use the StarterGui in this script since the Chat Messages are a part of the StarterGui.
local Players = game:GetService("Players")

-- Defining the variable for the RemoteEvent again
local PlayerEvent = ReplicatedStorage.PlayerEvent

PlayerEvent.OnClientEvent:Connect(function(player, state)
if state ==  "OnPlayerJoined" then
-- The message below will appear in the Chat when a Player Joins. The message is completely customizable by Font, Text Color, and Text Size!
              StarterGui:SetCore("ChatMakeSystemMessage", {
		        Text = "{System}: "..player.." has joined the game.",
	         	Color = Color3.new(1, 1, 1)
	     })

            elseif state == "OnPlayerLeft" then
              StarterGui:SetCore("ChatMakeSystemMessage", {
-- The message below will appear in the Chat when a Player Leaves. The message is completely customizable by Font, Text Color, and Text Size!
		                 Text = "{System}: "..player.." has left the game.",
		                 Color = Color3.new(1, 1, 1)
	                    })

            end 
end

And that's it! Test it out with someone else and it should work!
Section 2 (Intermediate)

This part of the tutorial assumes that you have a basic knowledge of scripting and Remote Events and an intermediate knowledge of Roblox’s Lua Chat System.

This section of the tutorial displays how you can make a more efficient version of Join and Leave Messages.

Some of you might be bothered that the Join and Leave messages are all in one channel, which is the main one, where everyone in the server speaks.

To prevent the main chat from being too cluttered, it would be better if we put the Join and Leaves Messages in a separate Chat channel to make the chat neater.

First we’re going to make it so we can see all the channels in chat so you’ll know what I mean.

Create a Local Script in StarterPlayerScripts. The name of the local script doesn’t matter.

The script below Gets All the modules we need to modify the Chat Settings.

local Chat = game:GetService("Chat")
local ClientChatModules = Chat:WaitForChild("ClientChatModules")
local ChatSettings = require(ClientChatModules:WaitForChild("ChatSettings"))

Now we can modify the default settings for the chat. In this case we’ll want the Channel Bar to show

ChatSettings.ShowChannelsBar = true

The final code in the local script should look like this:

local Chat = game:GetService("Chat")
local ClientChatModules = Chat:WaitForChild("ClientChatModules")
local ChatSettings = require(ClientChatModules:WaitForChild("ChatSettings"))

ChatSettings.ShowChannelsBar = true

After you finish writing the code, you will no longer need the local script open. You can now close it.

Play test in Studio, and when you’re in the game, open the chat and should see Bars that look like this:
image
These are the default Chat channels. These chat channels were always there, but the bars just weren’t visible.

You can now end the play test.

Its time we make the Join and Leave Messages. They’re going to appear in the System Channel so the chat will be more neater, which is the purpose of this section. To switch to the System Channel, simply click the System Channel Button on the Channel Bar.

Create a server script and place it in ServerScriptService. Once again, the name of the script doesn’t matter.

The following code defines the Roblox services we’re using for our script. We’ll need ServerScriptService and Players in this case along with the ChatService. We use WaitForChild because ChatServiceRunner only appears in ServerScriptService when we’re in the game.

We’ll also need to get the System Channel so the Join and Leave messages will appear in the System Chat Channel Only.

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

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

Now for the join and leave messages. They’re similar to the Join and Leave Messages from Section One, but this time they’ll appear in the System Channel.

-- When A Player Joins, the Join Message Appears in the System Channel
local function playerAdded(player)
	systemChannel:SendSystemMessage("{System}: " .. player.Name .. " has joined the game.")
end

-- When A Player Leaves, the Leaves Message Appears in the System Channel as well
local function playerRemoved(player)
	systemChannel:SendSystemMessage("{System}: " .. player.Name .. " has left the game.")
end

Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoved)

The final code in the script should be this:

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

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

local function playerAdded(player)
	systemChannel:SendSystemMessage("{System}: " .. player.Name .. " has joined the game.")
end


local function playerRemoved(player)
	systemChannel:SendSystemMessage("{System}: " .. player.Name .. " has left the game.")
end


Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoved)

And That’s it!

You can now play test in Studio, and when you do, the join and leave messages should appear in the System Channel. There will also be a little red icon that appears on the Channel Bar that lets you know someone joined and left.

I hoped this tutorial helped you. If you have any other questions, concerns, or if you ran into any issues, please let me know.

Credits for the rewrite:

@colbert2677
@LuiOG
@Expertcoderz
@levisurely

37 Likes

you only really need one remote event for this

3 Likes

This is good, although I recommend having it like {System}: Display Name (Real Username) has left the game.

Seeing the display name and the real username over a user when the join/leave would be better in the long run.

2 Likes

Thanks for the suggestion! I will edit that into the post when I can.

There’s no reason to introduce a network footprint for a join and leave notifier nor to do it from the server since LocalScripts are capable of using PlayerAdded and PlayerRemoving. You can have the client check for new and leaving players and send a message to the chat window.

If you are doing this from the server, you still don’t need to cross the network boundary yourself - use a system Channel or another appropriate channel and call SendSystemMessage. You could also alternatively create a system ChatSpeaker and have it say the message.

9 Likes

You can get flagged too since you are disrespecting. If you don’t like the topic then go read other tutorials, not disrespecting them.
Plus you could also say your comment respectfully. Not like that.

1 Like

Please read the context of the tutorial better.

Literally they just tell the learners to copy and paste the code. Although they do explain using comments, it’s hard for everyone to read. Plus, as @colbert2677 said, this isn’t the best way to make a join and leave message.

2 Likes

Rly like this tutorial! Especially for the people who don’t rly know that much scripting (which is me lol), you did a great job!

2 Likes

And I don’t even think this is a tutorial btw. The category is in community resources. If it would have been in tutorials, then yeah what you said might have made sense.

3 Likes

Nah, he ain’t disrespecting that’s just his opinion on what he thinks about this tutorial.

In the code where you “copy and paste” there are lines where it explains what the code does. I simply made this topic to help beginners make one. You’re free to call it useless, but I had good intentions, so if you think you can improve it, you can make your own.

Thanks for all your opinions on the tutorial everyone!

I understand that I may have made mistakes on this “tutorial”, but I simply wanted to help out beginners who didn’t know how to do this. I had good intentions. I didn’t create this tutorial to decrease the knowledge of others. Quite the opposite actually.

It may be unprofessional, and I’m sorry for that, but I did what I could to help given my current knowledge of scripting. If you don’t like the tutorial, then you can make a separate that’s way better.

Edit: To reduce confusion, I moved this topic to the Community Resource category.

I guess I don’t deserve my first “Nice Topic” badge I got from this topic…

Declare your Roblox services at the beginning of the script like this:
local SomeService = game:GetService("SomeService")
and then use the services through variables instead of having game.SomeService or game:GetService("TheSameService") multiple times in the script.

This goes for the Players, ReplicatedStorage and StarterGui services.

1 Like

dude don’t have to be so mean, it’s his first tutorial , respect yourself. Just tell him how to improve in a nicer way

3 Likes

What about my reply was mean-spirited? That reply was intended to offer advice about working with systems like this. I didn’t demean the tutorial nor the poster in any way, I just gave my advice in a frank manner. I don’t like loading my posts up with flavour text, it takes away from the point.

Whether or not it’s someone’s first tutorial or not, you want to aim to teach good habits and point towards alternative, potentially better solutions if the initial one seems to be lackluster. I apologise if you see offering advice as mean-spirited, but feel free to flag instead if you think there’s a real problem.

I said what I said: you don’t need to use networking features for a simple join notifier. Nothing mean about that. Don’t introduce features where unnecessary.

2 Likes

As I said before, I’m sorry if it seems unprofessional.
I’m not perfect at scripting. On the contrary, I’m more of a newbie.
I’m sorry if you expected a perfect tutorial in this post, but I made this tutorial to the best of my knowledge.
If you want to, you’re free to make a whole separate topic on this post to improve it without objection.

I don’t know even know what networking features mean. So, tell me in PMs if you want me to improve the post.

1 Like

Not the point. I didn’t open this thread with any expectations. The most I did was see a new post, read it and offer some advice I think would be helpful for improvements in working with systems like this. It’s not that deep nor is there any meaning beyond that. You’re free to listen to or ignore that advice at your own discretion, I’m not making a demand.

By “networking features” I’m referring to crossing the network boundary with remotes just to send a chat message, you don’t need to do that. Use remotes for things you actually need to replicate or communicate from the server to the client or vice versa.

1 Like

I really want your feedback. I want everyone’s feedback. I just don’t get the advice you’re saying, given my little skill in scripting right now.

I know this is a very late reply because I kind of forgot about this topic, but I took advice from all of you and managed to figure put a way to make a script that fit all the actual/not rude suggestions. (See credits below)

I’ve gained lots of experience since this topic was created so I’m going to rewrite this post by making it more of a tutorial than a resource. I’ll be adding an additional section that shows how to make Join and Leave messages in a separate channel. I’ll be adding a bonus too.

I hope you will all will find it helpful when I update it.

Credits for suggestions:
@colbert2677 (You helped the most)
@LuiOG (There will be one remote event for the first section of the tutorial rewrite and no remote events for the second section of rewrite since I won’t need to use the client for it).
@Expertcoderz (Thanks :slight_smile: )
@levisurely (Thanks :slight_smile: )

If there are any other suggestions, feel free to PM me or reply to this topic. I would really appreciate it.

5 Likes

Section One of the tutorial has just been rewritten.

You can see the updated tutorial above. I will be writing Section 2 when I can.

I really hope its a better tutorial this time and easier to understand. Let me know if it still needs lots of improvement!