Client chat messages not showing up

So i have a game when i type /e troll it makes it all red and ect but it also makes other people chat random things for them only to everyone
but i cant seem to get the players chats with chat service
here is a example i was trying to do
Local script :

local serverScriptService = game:GetService("Chat")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner").ChatService)
local Messages = {"Where are you","Come back","What door are you at","Where did you go"}
task.spawn(function()
		for i,v in pairs(game.Players:GetPlayers()) do
			if v ~= game.Players.LocalPlayer then
				local speaker = chatServiceModule:GetSpeaker(v.Name)
				local LastMessage = ""
			if not speaker then
				speaker = chatServiceModule:AddSpeaker(v.Name)
				speaker:SetExtraData("NameColor", nameColors[getNameValue(v.Name) % #nameColors + 1])
				speaker:JoinChannel("All")
				end
				task.wait(30)
				print("Started the wait")
				task.spawn(function()
				while task.wait(math.random(10,25)) do
					print("Chatted")
					local CurrentMessage = nil
					repeat
					CurrentMessage =	Messages[math.random(1,#Messages)]
						task.wait()
					until CurrentMessage ~= LastMessage
					
			speaker:SayMessage(Messages[math.random(1,#Messages)], "All")
					end
					end)
				end
			end
	end)
1 Like

Hello @nikos300! :happy1:
I am new at scripting, and I took your code and tried to fix it. Here is what I did!

local Players = game:GetService("Players")
local ChatService = game:GetService("Chat")
local Messages = {"Where are you","Come back","What door are you at","Where did you go"}
local function GetRandomMessage(lastMessage)
    local newMessage
    repeat
        newMessage = Messages[math.random(1, #Messages)]
    until newMessage ~= lastMessage
    return newMessage
end
Players.PlayerAdded:Connect(function(player)
    if player ~= Players.LocalPlayer then
        local speaker = ChatService:GetSpeaker(player.Name)
        if not speaker then
            speaker = ChatService:AddSpeaker(player.Name)
            speaker:SetExtraData("NameColor", nameColors[getNameValue(player.Name) % #nameColors + 1])
            speaker:JoinChannel("All")
        end
        local lastMessage = ""
        while true do
            task.wait(math.random(10, 25))
            local newMessage = GetRandomMessage(lastMessage)
            speaker:SayMessage(newMessage, "All")
            lastMessage = newMessage
        end
    end
end)

If you found this answer useful, do not forget to mark it as solved :white_check_mark:.
@Katastro5 :cool:

1 Like

Are you using the legacy chat system or the new one? This is how you check;

image

Hello @txcIove! :happy1:
I think the code @nikos300 provided doesn’t differentiate between the legacy chat system and the new one.

im using the legacy chat service

this is the general issue since its a local script it doesnt wanna run it on client
i know its supposed to be on server but i want it cliently done

im not 100% sure, but in these lines:
It looks like you’re adding a speaker , but since it’s wrapped in a for i,v loop, it’ll loop through all the speakers since you’re passing v.Name

speaker = chatServiceModule:AddSpeaker(v.Name)

speaker:SetExtraData(NameColor, nameColors[getNameValue(v.Name) % #nameColors + 1])|
speaker:JoinChannel(All)

you can clearly see that it gets the speakers too
the main problem is that i cant run these since its on client but i dont know how to do it else

You could have the localscript fire an event to the server where the server will have the functionaility then it fires it back to the client which the localscript recieves?

local event = game.ReplicatedStorage.Event
event:FireServer()
event.OnClientEvent:Connect(function()
      
end)
local event = game.ReplicatedStorage.Event
event.OnServerEvent:Connect(function(player)
      -- do your magic here
      event:FireClient(player)
end)

this isnt the issue the issue is that i cant make the messages in client and dont know i could do it in any diffrent way