How do I send a system message when a staff member joins the game?

I am thinking of detecting their group rank, and then sending a message when they join if their rank is a certain number, but I don’t know how to send system messages.

3 Likes

Hmm, what do you mean by system message?

2 Likes

I think he means a message like this: {System}: Your friend ROBLOX has joined the game.

1 Like

It’s a message sent in chat, like the your friend has joined message.

2 Likes

a similar thread has been made before, Make script post message in default chat? - #4 by Extuls

but in simple terms, the “ChatMakeSystemMessage” is a function of SetCore, you can research it more in depth here StarterGui | Documentation - Roblox Creator Hub.

StarterGui:SetCore("ChatMakeSystemMessage", {
	Text = "This is a system message"; --The chat message
	Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
	Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
	TextSize = 18 --Text size, defaults to 18
})

you could connect this to a RemoteEvent if you’d like the server to send messages instead of only the client. the code provided below is not written by me, and was written by @FilteredDev

server:

SendMessageEvent:FireClient(player, {
	Text = "This is a system message"; --The chat message
	Color = Color3.fromRGB(0, 255, 255); --Chat message color, defaults to white
	Font = Enum.Font.SourceSansBold; --Chat message font, defaults to SourceSansBold
	TextSize = 18 --Text size, defaults to 18
})

here we pass the arguments required for the ChatMakeSystemMessage “function” from the server to the client, and then we’ll have the client post the message to the chat.

client:

SendMessageEvent.OnClientEvent:Connect(function(configuration)
	StarterGui:SetCore("ChatMakeSystemMessage", configuration)
end)

i’ll clarify a bit, this is possible to do on the server only, you’ll have to dig into the lua chat system, I’ll provide a link to the documentation, Customizing In-Experience Text Chat | Documentation - Roblox Creator Hub.

1 Like

Ok well, first make a playeradded event, when the player joins use

to see if he is a certain rank in the group. Then if he is fire a remote event because chat messages can only be shown on a local script

SendMessage:FireAllClients({  --FireAllClients will send it to every player in the players server, you can also use SendMessage:FireClient(player Target, chatProperties)
  Text = “Hello World!”; --The message to be printed (Required)
  Color = Color3.fromRGB(0,255,215); --The colour of the output text (Optional, will default to a white-ish colour)
  Font = Enum.Font.SourceSans; --The font of the message (Optional, will default to SourceSans)
  FontSize = Enum.FontSize.Size18; --The size of the message (Optional, will defualt to Size18)

})

– example provided by someone, this is because you can only make chat messages appear on the chat on a local script, then on a local script pick it up

SendMessage.OnClientEvent:Connect(function(chatProperties) --Recieves the event sent from the player (excluding the player argument if we used :FireClient()

game:GetService(“StarterGui”):SetCore(“ChatMakeSystemMessage”,chatProperties) --Outputs the message to the client’s chat window
end

The client can then pick up the remote fired using this script, the firing example was not written by me

2 Likes

I don’t recommend this, you should look into the ChatService. This post was made before I fully understood the chat srvice

Anyway, the implementation here is to load up the ChatService in a server script with

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

Next, create a table of UserIds which hold staff members

local StaffMembers = {8094244, 1}

We next want to make a function that will send a SystemMessage to every chat speaker currently in the game, we can do this by doing

local function SendSystemMessageToAllSpeakers(msg, channel)
   for _, v in pairs(ChatService:GetSpeakers()) do
      v:SendSystemMessage(msg, channel)
   end
end

Finally, we define a function to fire when a player is added

local function PlayerAdded(plr)
   if table.find(StaffMembers, plr.UserId) then
      local formatStr = string.format("%s joined the game", plr.Name)
      SendSystemMessageToAllSpeakers(formatString, "All")
   end
end

for _, v in pairs(Players:GetPlayers()) do PlayerAdded(v) end --because the chat system takes a moment to load, a player may enter the game before it's fully loaded. We'll iterate over each player currently in the game
Players.PlayerAdded:Connect(PlayerAdded)

If you want to read any more into the Lua ChatSystem (and in extent the ChatService) You can do so here

11 Likes

yeah, this is however the method that most people use today, there are (like the example you provided) better methods of pulling this off, I think some people would consider the method I provided a simpler but inefficiant-ish way of doing this. correct me if I am wrong about anything here

1 Like