Sending a message to a user via the server

How would I send a message to a certain user via the chat system? In my admin command system, I would like to send a red warning message if a player does not have the right amount of arguments in their command or the player does not exist.

What’s your script so far? @NeonSignalYT

function throwError(player, reason)
	if reason == 1 then
		reason = "User does not exist/multiple users exist"
	elseif reason == 2 then
		reason = "Not enough arguments"
	end
end

-- commands

commands.to = function(mod, args)
	if args[1] then
		local subject = getPlayer(args[1])
		if subject then
			-- teleport them to the subject
		else
			throwError(mod, 1)
		end
	else
		throwError(mod, 2)
	end
end

In throwError(), I would like it to send reason to the player in red text.

Use this to check if the player exists:

for i, plr in pairs(game.Players:GetChildren()) do
   if plr = subject then
       --The command you want
   else
       throwError(mod, 1)
   do
end

btw im assuming the subject is the requested player

@NeonSignalYT Do you have a scripts that gets the amount of arguements that are used?

This is not my full code. I am getting the args before running the command function, and getting the player in the getPlayer function. My question is as follows: how do I send a message to a specific player from the server.

Fire a remote event to the client with the error message and use StarterGui:SetCore("ChatMakeSystemMessage", configTable)

You can see the format options for configTable here StarterGui:SetCore under ChatMakeSystemMessage.

If you’re using the new TextChatService, you can send a remote event to the client with the error message and call :DisplaySystemMessage(systemMessage) on a text channel. You can use rich text tags in the error message to display the color.

2 Likes

Do you want it some certain GUI to appear on the targeted player’s screen?

I was pretty clear of what I wanted, I now have the solution though, thank you for your help.