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
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)