Help with changing the chat color when a player types a command

I’m sort of new to scripting and I wanted to make the chat change to a purple-ish color when they type “(( /me {what player types} ))”.

image

and how would the chat know which body part the player was damaged at and ‘types’ it in?
Ex: “[!] you have been damaged in your lower torso and need to seek medical attention

Thank you in advance and sorry if asking too much I am slowly understanding how to script. :sweat_smile:

2 Likes

Here is a solution to what you want above the picture.

image
image

–Server script (ServerScriptService)

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

local function ChangeChatColor(player)
	local speaker = ChatService:GetSpeaker(player.Name) 
	speaker:SetExtraData("ChatColor", Color3.new(0.764706, 0.431373, 1)) --change color your custom
	task.wait()
	speaker:SetExtraData("ChatColor", Color3.new(1, 1, 1)) --change color back
end


RemoteEvent.OnServerEvent:Connect(ChangeChatColor)

–LocalScript (StarterGui)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg) --registers when a player writes something
	local values = msg:split(" ") --split msg into 2 parts
	if values[1] == "/me" then --if 1 part msg = "/me" then 
		RemoteEvent:FireServer() --send server player name (I use a server for everyone to see(change color))
	end
end)

2 Likes

Does that mean it splits between the players name and what they said?

this is what I’m trying to replicate like the whole thing is one color
image
(Without the numbers)
basically, there [Roblox name] says:

It mean, the message is divided into pieces according to where the gap is located.
EXAMPLE:
message: “hi my name is autumn” →
message[1] = hi
message[2] = my
message[3] = name
message[4] = is
message[5] = autumn

then I use message[1] to know if it equals = “/me”

3 Likes

But how would the text all be the same color? including the player’s name

using this:

local Color = Color3.new(0.764706, 0.431373, 1)
speaker:SetExtraData('NameColor', Color) --change name
speaker:SetExtraData("ChatColor", Color) --change text
3 Likes

thanks but can i edit this for other chat commands like /do and etc sorry again for all the questions

here is a bug though

image

Server script

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

local function ChangeChatColor(player)
	local speaker = ChatService:GetSpeaker(player.Name) 
	speaker:SetExtraData("NameColor", 0.764706, 0.431373, 1)
	speaker:SetExtraData("ChatColor", Color3.new(0.764706, 0.431373, 1)) --change color your custom
	task.wait()
	speaker:SetExtraData("ChatColor", Color3.new(1, 1, 1)) --change color back
end


RemoteEvent.OnServerEvent:Connect(ChangeChatColor)

Local script

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvents.RemoteEvent:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg) --registers when a player writes something
	local values = msg:split(" ") --split msg into 2 parts
	if values[1] == "/me" then --if 1 part msg = "/me" then 
		RemoteEvent:FireServer() --send server player name (I use a server for everyone to see(change color))
		
		player.Chatted:Connect(function(msg) --registers when a player writes something
			local values = msg:split(" ") --split msg into 2 parts
			if values[1] == "/do" then --if 1 part msg = "/me" then 
				RemoteEvent:FireServer() --send server player name (I use a server for everyone to see(change color))
			end
		end)
	end
end)

missing Color3.new() in NameColor

1 Like

sorry for your time but something else occurred
image

yes use can. (ignore this text)

1 Like

sorry for the trouble I fixed the bug thanks :smiley:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)
	local values = msg:split(" ")
	RemoteEvent:FireServer(values[1])
end)

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

local function ChangeChatColor(player,text)
	local speaker = ChatService:GetSpeaker(player.Name)
	
	if text == "/me" then
		local Color = Color3.new(0.764706, 0.431373, 1)
		Change(speaker,Color)
	end 
	if text == "/do" then
		local Color = Color3.new(1, 0.423529, 0.431373)
		Change(speaker,Color)
	end
end


RemoteEvent.OnServerEvent:Connect(ChangeChatColor)


function Change(speaker,Color)
	speaker:SetExtraData('NameColor', Color)
	speaker:SetExtraData("ChatColor", Color) 
	task.wait()
	Color = Color3.new(1, 1, 1)
	speaker:SetExtraData('NameColor', Color)
	speaker:SetExtraData("ChatColor", Color) 
end
1 Like

this will work (ignore this text)

did you combine the two? and where do I put this?

replace local script with this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")
local player = game.Players.LocalPlayer

player.Chatted:Connect(function(msg)
	local values = msg:split(" ")
	RemoteEvent:FireServer(values[1])
end)
1 Like

and server with this

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

local function ChangeChatColor(player,text)
	local speaker = ChatService:GetSpeaker(player.Name)
	
	if text == "/me" then
		local Color = Color3.new(0.764706, 0.431373, 1)
		Change(speaker,Color)
	end 
	if text == "/do" then
		local Color = Color3.new(1, 0.423529, 0.431373)
		Change(speaker,Color)
	end
end


RemoteEvent.OnServerEvent:Connect(ChangeChatColor)


function Change(speaker,Color)
	speaker:SetExtraData('NameColor', Color)
	speaker:SetExtraData("ChatColor", Color) 
	task.wait()
	Color = Color3.new(1, 1, 1)
	speaker:SetExtraData('NameColor', Color)
	speaker:SetExtraData("ChatColor", Color) 
end
2 Likes

And if you want to make this red message, you can use this local script (StarterGui):

game.StarterGui:SetCore("ChatMakeSystemMessage", {
	Text = "[!] Write Your Text"; 
	Font = Enum.Font.SciFi; 
	Color = Color3.new(0, 0.4, 1);
	FontSize = Enum.FontSize.Size96;
})
2 Likes