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.