I want to create a script that will allow all players to see a chat channel, but only players on certain teams will be able to speak there.
I keep getting an error that my script displays saying “Error checking teams” whenever the script tries to check which team the player is on.
Most of the script I took parst from Adding Chat Channels accessible for players of a certain rank in a group
I have looked all over in Lua Chat System in the developer API for what to use
I have tried to instead of trying to find the name of the team players are on (player.name.team), just find the team path. (player.team)
I have changed the if statement from using a bunch of or statements, to an array of all the authorized/unauthorized teams
local ServerScriptService = game:GetService("ServerScriptService")
local ChatService = require(ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
local ChannelName = "ATC"
local Channel = ChatService:AddChannel(ChannelName) -- makes the channel to speak in and edits settings
Channel.Joinable = false
Channel.AutoJoin = false
Channel.WelcomeMessage = "Only Authorized Personel may speak here"
local ATC = game:GetService("Teams")["Air Traffic Control"] -- lists all teams in game
local Pilot = game:GetService("Teams")["Pilots"] -- (I made sure to coppy paste these)
local Managers = game:GetService("Teams")["Management"]
local Workers = game:GetService("Teams")["Ground Crew"]
local Atend = game:GetService("Teams")["Attendants"]
local civilian = game:GetService("Teams")["Passengers"]
local Security = game:GetService("Teams")["Security"]
local Staff = game:GetService("Teams")["Staff"]
local Authorized = {ATC, Pilot, Managers, Workers} -- teams who can speak in the channel
local Unathorized = {Atend, civilian, Security, Staff} -- teams who cannot speak in the channel
ChatService.SpeakerAdded:Connect(function(PlayerName) -- fires when a player joins
local Player = game:GetService("Players"):FindFirstChild(PlayerName)
local Speaker = ChatService:GetSpeaker(PlayerName)
Speaker:JoinChannel(ChannelName)
Channel:MuteSpeaker(PlayerName, "Only Authorized Personel may speak here.", 1000) -- Mutes speakers in ATC channel until their team is assigned
while Player do -- in hopes that if the player leaves the loop will stop
wait(10)
if Player.Team == Authorized then
Channel:UnmuteSpeaker(PlayerName) -- unmutes speaker
print("Unmuted")
elseif Player.Team == Unathorized then
Channel:MuteSpeaker(PlayerName, "Only Authorized Personel may speak here.", 11) -- mutes Speaker
print("Muted")
else
warn("Error checking teams") -- this goes off every time
end
end
end)