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)
Hello @nikos300!
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 . @Katastro5
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
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)