Spectate Function Not Working

Hello, this spectate function doesn’t open the spectate ui during any point of the game even when the status isn’t set to intermission. I’d also like to know how I could remove players that are in the lobby from the playerlist table. Any help is appreciated.

SpectateButton.Activated:Connect(function()
	local Player = Players.LocalPlayer
	local Humanoid = Player.Character.Humanoid
	
	if #Players:GetPlayers() == 1 then return end
	if Player.Status.Value ~= "Lobby" then return end
	if RoundInfo.Status.Value == "Intermission" then return end
	
	if Spectate.Visible == false then
		Spectate.Visible = true
	else
		Spectate.Visible = false
		PlayerName.Text = "Spectating Nobody"
		Camera.CameraSubject = Humanoid
	end
end)

NextPlayer.Activated:Connect(function()
	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)
1 Like

Is the script enables a Frame or ScreenGui?

1 Like

The script effects the visibility of a frame.

Can you confirm which line errors? Also, could you confirm which line stopped working using print statements?

There are no errors, it worked since I added the Intermission return end, for some reason it stopped working after I added that line.

To remove players that have left, make a function that runs on PlayerLeaving event with the players name/userid. Run a for loop through your table until this player is found. Then remove that index.

A little unrelated, but you could turn this:

into:

if #Players:GetPlayers() == 1 or Player.Status.Value ~= "Lobby" or RoundInfo.Status.Value == "Intermission" then return end

Couldn’t you :thinking:

Optimize, Adapt, Overcome. :smirk:

Fr you gotta keep your if statements clean.

Me when I learned how to do one line functions in python :smirk:

1 Like