Ultimately I want to create 3 chat channels, “Lobby”, “Survivors”, and “Killer”. When players join they are put into the “Lobby” chat. Once the game starts, the survivors go into the “Survivors” chat and the one killer goes to the “Killer” chat, so that they cannot communicate. When players die they go to the lobby.
To achieve this I need to be able to add a player’s ChatSpeaker to a channel. This is where I am having problems, when I try to call a method on a ChatSpeaker I receive an error:
This is the code that I am using:
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local main = ChatService:GetChannel("All")
local lobby = ChatService:AddChannel("Lobby") -- The channel "Lobby" is now added to the game.
ChatService.SpeakerAdded:Connect(function(speaker)
local spk = ChatService:GetSpeaker(speaker) -- This is the chatspeaker for the speaker that has just joined.
print(spk:IsInChannel("All")) -- true
print(spk:IsInChannel("Lobby")) -- false.
main:MuteSpeaker(speaker, "You are being added to the Lobby chat.") -- Mutes player in all.
speaker:JoinChannel("Lobby")
print(spk:IsInChannel("Lobby")) -- I expect this to be true?
end)
I seem to get this same error on different methods, such as “LeaveChannel”. I don’t see where I am going wrong here, I have read the Lua Chat System API more than 3 times and I don’t spot my mistake, and I cannot find a relevant post elsewhere, though I have looked.
Oh for… Yeah, I just forgot to change the variable I was calling the method on, how stupid, sorry.
The problem I was having originally was kicking the players from “All” chat and placing them into the “Lobby” chat. This is the code I am using for this:
local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local main = ChatService:GetChannel("All")
local lobby = ChatService:AddChannel("Lobby") -- The channel "Lobby" is now added to the game.
ChatService.SpeakerAdded:Connect(function(speaker)
local spk = ChatService:GetSpeaker(speaker) -- This is the chatspeaker for the speaker that has just joined.
print(spk:IsInChannel("All")) -- true
print(spk:IsInChannel("Lobby")) -- false.
spk:JoinChannel("Lobby")
main:KickSpeaker(speaker, "You are being added to the Lobby chat.") -- Mutes player in all.
print(spk:IsInChannel("Lobby")) -- I expect this to be true?
end)
The user is then unable to speak in any chat at all, even though they SHOULD be in the Lobby chat, and the script stops. Am I not able to kick players from the “All” channel?