Or is there a reason as to why there’s no way to do it? And is there a way for the chat to show up for all players then in the bubble? Kinda useless if it only shows for the client
See if any of the methods available are of any use to you.
The methods I suggested are server side only by design. Use server side for this.
Alternatively, just post a system message designed to mimic a normal chat message when you call :Chat (once again, you will need to have some communication to the server for this).
To add onto that, here’s an example code which makes the player’s chat speaker say a message
local ChatService = require(game:GetService("ServerScriptService").ChatServiceRunner.ChatService)
local function Chat(plr, msg)
local speaker = ChatService:GetSpeaker(plr.Name)
if not speaker then
return
end
speaker:SayMessage(msg, "All", {})
end
Chat(game.Players.NinjoOnline, "I was forced to say this")
(typed on a new phone with a bad autocorrect so forgive any typos)
There’s an event under the Chat service called Chatted. This is fired whenever :Chat() is called. Use this as a determinant to when to send messages to the chat bar.
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Chat = game:GetService("Chat")
-- CSR is not implicit, you need to wait for it
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)
Chat.Chatted:Connect(function (adornee, message)
-- Assuming adornee is a character head
local player = Players:GetPlayerFromCharacter(adornee.Parent)
if player then
local speaker = ChatService:GetSpeaker(player.Name)
if speaker then
speaker:SayMessage(message, "All", {})
end
end
end)
Tailoring it to non-players or for better control/checking is up to you. This will, however, log anything done from Chat.Chat (like your code sample above) and send it back to the Lua Chat System.
@Amiaa16 Why are you handling nil cases with a return?
if speaker then
speaker:SayMessage(msg, "All", {})
end
local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Chat = game:GetService("Chat")
local ChatServiceRunner = ServerScriptService:WaitForChild("ChatServiceRunner")
local ChatService = require(ChatServiceRunner.ChatService)
print(1)
Chat.Chatted:Connect(function(adornee, message)
print(2)
-- Assuming adornee is a character head
local player = Players:GetPlayerFromCharacter(adornee.Parent)
if player then
local speaker = ChatService:GetSpeaker(player.Name)
if speaker then
speaker:SayMessage(message, 'All', {})
end
end
end)
Doesn’t even print 2 (prints 1) when I chat. Either using :Chat() or just manually typing a chat.
You sure about that, or did you not test properly? I inserted the exact code I gave you along with the prints and I fired off a test chat - it printed as expected, which is the opposite of what you reported.
Script in ServerScriptService with a line to check if my code worked:
Does the :Chat() have to be in the server? I’m firing it from the client
EDIT Nvm that didn’t work either
local Chat = game:GetService('Chat')
local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')
local ChatServiceRunner = ServerScriptService:WaitForChild('ChatServiceRunner')
local ChatService = require(ChatServiceRunner.ChatService)
print(1)
Chat.Chatted:Connect(function(adornee, message)
print(2)
-- Assuming adornee is a character head
local player = Players:GetPlayerFromCharacter(adornee.Parent)
if player then
local speaker = ChatService:GetSpeaker(player.Name)
if speaker then
speaker:SayMessage(message, 'All', {})
end
end
end)
Chat:Chat(workspace.NinjoOnline.Head, "test")
Chat bubble appears, but nothing shows in the chat bar, nor does print(2) print
EDIT
Full script
local Chat = game:GetService('Chat')
local Players = game:GetService('Players')
local ServerScriptService = game:GetService('ServerScriptService')
local ChatServiceRunner = ServerScriptService:WaitForChild('ChatServiceRunner')
local ChatService = require(ChatServiceRunner.ChatService)
print(1)
Chat.Chatted:Connect(function(adornee, message)
print(2)
-- Assuming adornee is a character head
local player = Players:GetPlayerFromCharacter(adornee.Parent)
if player then
local speaker = ChatService:GetSpeaker(player.Name)
if speaker then
speaker:SayMessage(message, 'All', {})
end
end
end)
print(3)
workspace:WaitForChild("NinjoOnline")
Chat:Chat(workspace.NinjoOnline.Head, "test")
print(4)
Both of my scripts were ran from the server and worked fine as shown by the above repro. What is your current implementation setup and use case for involving the client?