Im making a game thats supposed to make npcs look like players But i have a problem I Already know how to make npcs chat but it dosent apear in the chat box
How do i make chat apear in the chat box from npcs?
1 answer
Whenever NPC chats (or when ChatService.Chatted is fired), you will make a system message by using StarterGui:SetCore("ChatMakeSystemMessage")
This LocalScript must be inside StarterGui.
local Players = game:GetService("Players")
local ChatService = game:GetService("Chat")
local StarterGui = game:GetService("StarterGui")
ChatService.Chatted:Connect(function(partOrCharacter, message, color)
if partOrCharacter:IsA("Model") then
if partOrCharacter:FindFirstChildOfClass("Humanoid") then
local player = Players:GetPlayerFromCharacter(partOrCharacter)
if player ~= nil then -- if the one who chatted is an NPC
local configTable = {
Text = string.format("[%s]: %s", partOrCharacter.Name, message),
}
StarterGui:SetCore("ChatMakeSystemMessage", configTable) -- makes the message appear in chat box
end
else
local configTable = {
Text = string.format("[%s]: %s", partOrCharacter.Name, message),
}
StarterGui:SetCore("ChatMakeSystemMessage", configTable) -- makes the message appear in chat box
end
elseif partOrCharacter:IsA("BasePart")
local character = partOrCharacter:FindFirstAncestorWhichIsA("Model")
local humanoid = character:FindFirstChildWhichIsA("Humanoid")
if character and humanoid then
local configTable = {
Text = string.format("[%s]: %s", character.Name, message),
}
StarterGui:SetCore("ChatMakeSystemMessage", configTable) -- makes the message appear in chat box
else
local configTable = {
Text = string.format("[%s]: %s", partOrCharacter.Name, message),
}
StarterGui:SetCore("ChatMakeSystemMessage", configTable) -- makes the message appear in chat box
end
end
end)
13 comments
How do i reply to other posts
what do you mean?
Dosent work i cant see the chaty
Ok I edited the script, it should work now.
You forgot to put "then" I Fixed it and it worked But how do i color the names of the npcs
npc's name color
in the config table, you can add a new key called "Color" and make that value a Color3
wdym key give me an example
local configTable = {["Text"] = string.format("[%s]: %s", partOrCharacter.Name, message), ["Color"] = Color3.fromRGB(0,0,255),}
try that and it will make the message blue in chat
I Got this error " Expected identifier when parsing expression, got '}'"
wdym there's nothing wrong
anyways how do you get the npc's name color?
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
appear* sorry