Hello, this function manages the spectating feature, although there are a few things that need to be changed that I’m not sure on how I could do it, basically the player is assigned a string value displaying their status. How could I make this where only players with the status as Lobby can spectate and remove people with that status from the PlayerList table. Help is appreciated.
NextPlayer.Activated:Connect(function()
if #Players:GetPlayers() == 1 then return end
local PlayerList = Players:GetPlayers()
table.remove(PlayerList, table.find(PlayerList, Players.LocalPlayer))
local Player = PlayerList[Position + 1]
local Humanoid = Player.Character.Humanoid
if Humanoid then
Position = (Position + 1) % #PlayerList
Camera.CameraSubject = Humanoid
PlayerName.Text = "Spectating "..Player.Name
end
end)
For removing the players with the Lobby tag, try looping through the PlayerList and see if the player has the Lobby tag. If they do then remove the player from the PlayerList.
For preventing people with the Lobby tag from spectating. Just detect if the player has the Lobby tag. If they do have it, then just cancel the script. (This should be put right below the line where it detects if theres only 1 player).
You can loop through the players and check their status, like this:
NextPlayer.Activated:Connect(function()
if #Players:GetPlayers() == 1 then return end
local PlayerList = {}
for _, Plr in pairs(Players:GetPlayers()) do
if Plr.Status.Value ~= "Lobby" and Plr.Name ~= Players.LocalPlayer.Name then
table.insert(PlayerList, Plr)
end
end
local Player = PlayerList[Position + 1]
local Humanoid = Player.Character.Humanoid
if Humanoid then
Position = (Position + 1) % #PlayerList
Camera.CameraSubject = Humanoid
PlayerName.Text = "Spectating "..Player.Name
end
end)