Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 2 years ago

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

0
appear* sorry ImNotAN00b_0kay 31 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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)
0
How do i reply to other posts ImNotAN00b_0kay 31 — 2y
0
what do you mean? T3_MasterGamer 2189 — 2y
0
Dosent work i cant see the chaty ImNotAN00b_0kay 31 — 2y
0
Ok I edited the script, it should work now. T3_MasterGamer 2189 — 2y
View all comments (9 more)
0
You forgot to put "then" I Fixed it and it worked But how do i color the names of the npcs ImNotAN00b_0kay 31 — 2y
0
npc's name color ImNotAN00b_0kay 31 — 2y
0
in the config table, you can add a new key called "Color" and make that value a Color3 T3_MasterGamer 2189 — 2y
0
wdym key give me an example ImNotAN00b_0kay 31 — 2y
0
local configTable = {["Text"] = string.format("[%s]: %s", partOrCharacter.Name, message), ["Color"] = Color3.fromRGB(0,0,255),} T3_MasterGamer 2189 — 2y
0
try that and it will make the message blue in chat T3_MasterGamer 2189 — 2y
0
I Got this error " Expected identifier when parsing expression, got '}'" ImNotAN00b_0kay 31 — 2y
0
wdym there's nothing wrong T3_MasterGamer 2189 — 2y
0
anyways how do you get the npc's name color? T3_MasterGamer 2189 — 2y
Ad

Answer this question