Since YouTube tutorials about this topic are outdated (using LegacyChatService), I decided to make an updated tutorial (using TextChatService).
The steps in this tutorials are based from the outdated YT ones but modified for TextChatService.
If you don't know why these steps are carried out, please watch Roblox Studio tutorials on YouTube or look up on the Developer Forum.
Add a script in ServerScriptService and write the following (it's simple to understand so I won't have to explain)
game:GetService("Players").PlayerAdded:Connect(function(Player)
print(Player.Name, "has joined.") --> Or Player.DisplayName :)
end)
game:GetService("Players").PlayerRemoving:Connect(function(Player)
print(Player.Name, "has left.") --> Or Player.DisplayName :)
end)
-- You can Test play and check the Output.
- Add a Folder in ReplicatedStorage, name it as PlayerEvents (however you like).
- Add 2 RemoteEvent (Joining, Leaving) (again however you like)
- I'll assume as PlayerEvents, Joining & Leaving for better clarity and avoiding any confusion.
local PlayerEvents = game:GetService("ReplicatedStorage"):FindFirstChild("PlayerEvents")
game:GetService("Players").PlayerAdded:Connect(function(Player)
PlayerEvents:FindFirstChild("Joining"):FireAllClients(Player)
end)
ggame:GetService("Players").PlayerRemoving:Connect(function(Player)
PlayerEvents:FindFirstChild("Leaving"):FireAllClients(Player)
end)
-- FireAllClients for displaying Chat Message to everyone.
- Add a LocalScript in StarterPlayerScripts and write the following.
local PlayerEvents = game:GetService("ReplicatedStorage"):FindFirstChild("PlayerEvents")
PlayerEvents:FindFirstChild("Joining").OnClientEvent:Connect(function(Player)
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(`<font color='#ffffff'>{Player.Name.. " has joined."}</font>`)
end)
PlayerEvents:FindFirstChild("Leaving").OnClientEvent:Connect(function(Player)
game.TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage(`<font color='#ffffff'>{Player.Name.. " has left."}</font>`)
end)
--> Or Player.DisplayName :)