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

how i do whisper command using a chatspeaker?

Asked by 3 years ago

how i do whisper command using a chatspeaker I tried this:

local Chat = game:GetService("Chat")
local plrs = game:GetService("Players")
local serverScriptService = game:GetService("ServerScriptService")
local chatServiceModule = require(serverScriptService:WaitForChild("ChatServiceRunner").ChatService)

local ReplicatedModules = Chat:WaitForChild("ClientChatModules")
local ChatModules = Chat:WaitForChild("ChatModules")
local ChatConstants = require(ReplicatedModules:WaitForChild("ChatConstants"))
local speaker = chatServiceModule:AddSpeaker("ROBLOX")
local messages = {
    ", you are awesome!",
    ", you are special!",
    ", i like you",
    ", i like you the way you are"
}
speaker:JoinChannel("All")
speaker:SetExtraData("NameColor", Color3.new(0, 132, 255))
speaker:SayMessage("I am fake, sorry :(")
speaker:SayMessage ("You can say: !message and i will send you a message :)")

serverScriptService:WaitForChild("ChatServiceRunner").ChatService:Clone().Parent = workspace
for i, v in pairs(chatServiceModule:GetChannelList()) do
    print(v)
end

local function GetWhisperChannelPrefix()
    if ChatConstants.WhisperChannelPrefix then
        return ChatConstants.WhisperChannelPrefix
    end
    return "To "
end

function GetWhisperChannelId(userName)
    return GetWhisperChannelPrefix() .. userName
end


local function plr_chatted(player, message)
    if string.lower(message) == "!message" then
        local number = table.getn(messages)
        local random = math.random(1, number)
        local channelObj = GetWhisperChannelId(player.Name)
        if channelObj == nil then warn("Erro: canal não encontrado!") return end
        speaker:JoinChannel(channelObj.Name)
        speaker:SayMessage(messages[random])
    end
    speaker:JoinChannel("All")
end

for i, player in pairs(plrs:GetPlayers()) do
    player.Chatted:Connect(function(message)
        plr_chatted(player, message)
    end)
    speaker:SayMessage("Hi "..player.Name.."!")
end

plrs.PlayerAdded:Connect(function(player)
    speaker:SayMessage("Hi "..player.Name.."!")
end)

https://pastebin.com/2m5uVPfS

1 answer

Log in to vote
0
Answered by 3 years ago

PROBLEM FIXED, MODERATORS PLS CLOSE THIS

0
change the title to (Fixed) then leave it, do not delete the question CrazyCats84 154 — 3y
Ad

Answer this question