Spectate players that are only in a round

Hello, I am a new scripter, and I have manged to make a spectate system using YT tutorials, but I want it to spectate players that are in a round and not the players in the lobby.

I have a script that gives the player a bool value when a player is in a round, if they die they lose the bool value

It’s defined in another script, in server script service.

local GameTag = Instance.new("BoolValue")
				GameTag.Name = "GameTag"
				GameTag.Parent = player.Character

my spectate system script:

local spectateMain = script.Parent:WaitForChild("SpectateMain")

local spectateBtn = script.Parent:WaitForChild("SpectateButton")


local cam = workspace.CurrentCamera


local plrs = {}

for i, plr in pairs(game.Players:GetPlayers()) do

	if plr ~= game.Players.LocalPlayer then table.insert(plrs, plr) end
end


game.Players.PlayerAdded:Connect(function(plr)
	table.insert(plrs, plr)
end)

game.Players.PlayerRemoving:Connect(function(plr)
	table.remove(plrs, plrs[plr])
end)


local currentlySpectating = 1


spectateBtn.MouseButton1Click:Connect(function()

	if #plrs < 1 then return end

	spectateMain.Visible = not spectateMain.Visible
end)



spectateMain.LeftButton.MouseButton1Click:Connect(function()

	if currentlySpectating > 1 then 
		currentlySpectating = currentlySpectating - 1

	else
		currentlySpectating = #plrs
	end
end)


spectateMain.RightButton.MouseButton1Click:Connect(function()

	if currentlySpectating < #plrs then 
		currentlySpectating = currentlySpectating + 1

	else
		currentlySpectating = 1
	end
end)



game:GetService("RunService").RenderStepped:Connect(function()

	if #plrs < 1 then spectateMain.Visible = false end


	if spectateMain.Visible == true then

		cam.CameraType = Enum.CameraType.Scriptable

		local playerSpectating = plrs[currentlySpectating]
		if not playerSpectating then playerSpectating = plrs[1] end

		local char = playerSpectating.Character

		if char and char:FindFirstChild("HumanoidRootPart") then 

			local hrp = char.HumanoidRootPart

			local pos = hrp.Position + (hrp.CFrame.UpVector - hrp.CFrame.LookVector) * 10

			cam.CFrame = CFrame.new(pos, hrp.Position)
		end

		spectateMain.PlayerName.Text = playerSpectating.Name


	else

		cam.CameraType = Enum.CameraType.Custom
	end
end)

I have no clue as to link the two, so if you could explain in detail please, it would be much apricated.

2 Likes

You can hide the gui spectate button when a round is in match, what I would do is make a part surrounding the whole lobby so if the player touches the part, it deletes the gui from his screen and for the rounds, I would make another part surrounding the whole map match and when player(s) touches it then it clones it to their screen showing the gui for them, the one used to clone would go in server storage or replicatedstorage, server storage is recommended for optimization and the one that gets cloned should go into PlayerGui.

Umm, that was not my original problem, but now that i am thinking about it this is a problem. If I can define the bool value in the script, we could try and make it so players that have this bool value can not use the spectate system, + if a player does not have this bool value players can not spectate players that are in the lobby

My scripting knowledge is rlly limited btw.

uh, why did you delete your post?

I don’t think I said what you wanted, the original post was if the boolean value == true then hide gui and if it is false then show gui

ok, but still no way to solve this problem

1 Like

You could put the players of the round in one folder/module and those in the lobby in another, always placing it in ReplicatedStorage.
image

local Teams = {
    Round = {
	    "Player1"
    },
	Lobby = {
	    "Player2"
    }
}
return Teams

there is already a bool value that i can use, just don’t how to properly define and use it in my the script

Spectate (LocalScript)
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")

local spectateMain = script.Parent:WaitForChild("SpectateMain")
local spectateBtn = script.Parent:WaitForChild("SpectateButton")

local cam = workspace.CurrentCamera
local Teams = Storage:WaitForChild("Teams")
local Watch = Teams:WaitForChild("Round")

local currentlySpectating = 1
spectateBtn.MouseButton1Click:Connect(function()
    if #Watch < 1 then return end
    spectateMain.Visible = not spectateMain.Visible
end)

spectateMain.LeftButton.MouseButton1Click:Connect(function()
    if currentlySpectating > 1 then 
	    currentlySpectating = currentlySpectating - 1
	else
    	currentlySpectating = #Watch
    end
end)

spectateMain.RightButton.MouseButton1Click:Connect(function()
    if currentlySpectating < #Watch then 
	    currentlySpectating = currentlySpectating + 1
	else
    	currentlySpectating = 1
    end
end)

game:GetService("RunService").RenderStepped:Connect(function()
    if #Watch < 1 then spectateMain.Visible = false end
    if spectateMain.Visible == true then
    	cam.CameraType = Enum.CameraType.Scriptable
	    local playerSpectating = Watch[currentlySpectating]
	    if not playerSpectating then
		    playerSpectating = Watch[1]
		end
    	local char = playerSpectating.Value
	    local hrp = char.HumanoidRootPart
	    local pos = hrp.Position + (hrp.CFrame.UpVector - hrp.CFrame.LookVector) * 10
	    cam.CFrame = CFrame.new(pos, hrp.Position)
		spectateMain.PlayerName.Text = playerSpectating.Name
    else
	    cam.CameraType = Enum.CameraType.Custom
	end
end)
TeamsManager (Script)
local Players = game:GetService("Players")
local Storage = game:GetService("ReplicatedStorage")

local List = Instance.new("Folder",Storage)
List.Name = "Teams"
local Lobby = Instance.new("Folder",List)
Lobby.Name = "Lobby"

Players.PlayerAdded:Connect(function(Player)
    local Obj = Instance.new("ObjectValue",Lobby)
    Obj.Name = Player.Name
    Obj.Value = Player.Character
end)

Players.PlayerRemoving:Connect(function(Player)
    local PlayerInList = List:FindFirstChild(Player.Name,true)
    if PlayerInList then
	    PlayerInList:Destroy()
    end
end)
About the rounds

Use this function when the round starts:

function PlayersForTheRound()
    local Storage = game:GetService("ReplicatedStorage")
    local List = Storage:WaitForChild("Teams")
    local Round = List.Lobby:Clone()
    Round.Name = "Round"
    Round.Parent = List
end

Use this function when the round is over:

function FinishRound()
    local Storage = game:GetService("ReplicatedStorage")
    local List = Storage:WaitForChild("Teams")
    List.Round:Destroy()
end

Locations:
image

1 Like

local GameTag = Instance.new(“BoolValue”)
GameTag.Name = “GameTag”
GameTag.Parent = player.Character