Hi, I wanted to ask how could i make a npc say something and then that thing goes to chat
1 Like
If you want an NPC to send a message to the chat box for all players to see, you can use a RemoteEvent to communicate between the server and the client. The server will trigger the event when the NPC needs to say something, and the client will handle displaying the message in the chat.
When you want the NPC to speak, fire this event from the server, sending the message as an argument. On the client side, listen for the event using .OnClientEvent
and display the message in the chat using TextChatService.TextChannels.RBXGeneral:DisplaySystemMessage("YOUR_MESSAGE_HERE")
.
Here’s a basic example of how this can be set up:
Server Script (inside ServerScriptService
)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SendNPCMessage = ReplicatedStorage:FindFirstChild("SendNPCMessage")
if SendNPCMessage then
SendNPCMessage:FireAllClients("Hello, traveler! Welcome to the game.")
end
Server Script (inside ServerScriptService
)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:FindFirstChild("REMOTE_EVENT")
local TextChatService = game:GetService("TextChatService")
if RemoteEvent then
RemoteEvent.OnClientEvent:Connect(function(message)
local chatChannel = TextChatService.TextChannels.RBXGeneral
if chatChannel then
chatChannel:DisplaySystemMessage("[NPC] " .. message)
end
end)
end
Hope this helps
1 Like
thank you sir hows your day thanks for the help this is becuase of 30 limit