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

Why does my script involving the Chat API not work?

Asked by
016er 9
3 years ago

I had asked this in the Devforum previously, however I haven't still gotten an answer from there, so I'm asking here.

I have made a script where I want to make a speaker and have said speaker talk in the chat publicly.

Initially it worked, however didn’t show up within the chat itself (a print that came with the message showed up regardless). I figured out that the issue was that they were not in the “All” channel, and made according changes. Now the script doesn’t seem to run at all as it doesn’t print, and I’m afraid it’s endlessly waiting for the “All” channel, because it doesn’t seem to get past that point.

I've included the Localscript below, which is parented to the StarterPack.

local Chat = game:GetService("Chat")
local CS = require(Chat:WaitForChild('ChatServiceRunner').ChatService)
local name = "CustomSpeaker"

while true do
    wait(.5)
    local waitchannel = CS.ChannelAdded:Wait()
        if waitchannel == "All" then
            break
        end
end

local speakerr = CS:AddSpeaker(name)
speakerr:JoinChannel("All")

local function SayMSG(speaker, msg, channel)
    speaker:SayMessage(msg, channel)
end

while true do
    wait(5)
    SayMSG(speakerr, "Test message", "All")
    print 'spoke'
end

Answer this question