Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make chat apear in the chat box from npcs?

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

1 comment

0

appear* sorry

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

0

How do i reply to other posts

0

what do you mean?

0

Dosent work i cant see the chaty

0

Ok I edited the script, it should work now.

0

You forgot to put "then" I Fixed it and it worked But how do i color the names of the npcs

0

npc's name color

0

in the config table, you can add a new key called "Color" and make that value a Color3

0

wdym key give me an example

0

local configTable = {["Text"] = string.format("[%s]: %s", partOrCharacter.Name, message), ["Color"] = Color3.fromRGB(0,0,255),}

0

try that and it will make the message blue in chat

0

I Got this error " Expected identifier when parsing expression, got '}'"

0

wdym there's nothing wrong

0

anyways how do you get the npc's name color?

This discussion is preserved as it was. New answers, comments, and votes are closed.