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)
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.
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
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)
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.
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?