Spectate only player with value true

Hello i need help for make system player spectate only player with value true

exemple : you have value name game and i need to make people can spec only people with the value game true but i don’t know to make this :’(

here you have a basic script

cam = game.Workspace.CurrentCamera

local bar = script.Parent.Bar
local title = bar.Title
local prev = bar.Previous
local nex = bar.Next
local button = script.Parent.Button

function get()
	for _,v in pairs(game.Players:GetPlayers())do
		if v.Name == title.Text then
			return(_)
		end
	end
end


local debounce = false
button.MouseButton1Click:connect(function()
	if debounce == false then debounce = true
		bar:TweenPosition(UDim2.new(.5,-100,0.88,-50),"In","Linear",1,true)
		pcall(function()
				title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
	elseif debounce == true then debounce = false
		pcall(function() cam.CameraSubject = game.Players.LocalPlayer.Character.Humanoid end)
			bar:TweenPosition(UDim2.new(-1,-100,0.88,-50),"In","Linear",1,true)
		end
end)

prev.MouseButton1Click:connect(function()
	wait(.1)
	local players = game.Players:GetPlayers()
	local num = get()
	if not pcall(function() 
		cam.CameraSubject = players[num-1].Character.Humanoid
		end) then
		cam.CameraSubject = players[#players].Character.Humanoid
	end
pcall(function()
				title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
end)

nex.MouseButton1Click:connect(function()
	wait(.1)
	local players = game.Players:GetPlayers()
	local num = get()
	if not pcall(function() 
		cam.CameraSubject = players[num+1].Character.Humanoid
		end) then
		cam.CameraSubject = players[1].Character.Humanoid
	end
pcall(function()
				title.Text = game.Players:GetPlayerFromCharacter(cam.CameraSubject.Parent).Name
		end)
end)

the ui like this
zqdz

thank to people help me
and sorry my English is bad :’(

If you’re asking how to make it so that players can only spectate people with a specific value marked true then you can make a value inside of the player that is marked false upon joining and once they meet the requirements of being spectated mark it true, then on the spectate menu when scrolling through the player make an if statement that checks if the value is true inside of the player and if it is run all of the code.

Hope this helps! :christmas_tree:

I don’t know how to do this :expressionless:

Oh, well make a function that runs when a player joins the game like this:

game.Players.PlayerAdded:Connect(function(player)
	local value = Instance.new("BoolValue")
	value.Name = "Spectate"
	value.Value = false
	value.Parent = player
end)

Put that inside of a script in server script service. After that you want to set it to true so that they can be spectated so make a script where it sets it to true, you can find the value by doing

local value = game.Players.LocalPlayer:FindFirstChild("SpectateValue")

And in your spectate script that you provided you just check if the value is true in the player before you do anything.