I have this spectate script which is working on all players. What I’m looking for is, how to specify players with specific tags (player:WaitForChild(“Killer”) or player:WaitForChild(“Victim”) so the player who spectates, will see only these players. Help much appreciated!
-- Our local script!
local spectateFrame = script.Parent.SpectateFrame
local button = script.Parent.SpectateButton
local openNow = true
local position = 1 -- New variable!
local playerList = {}
local cam = workspace.CurrentCamera -- Camera variable!
local function updatePlayerList(exemptPlayer) -- This player won't be added in, if specified
for _, plr in pairs(game.Players:GetPlayers()) do
if plr ~= exemptPlayer and not table.find(playerList, plr) then -- If the player isn't exempt and not in it already, add them in!
table.insert(playerList, plr)
end
end
end
local function updateCamera(playerSubject) -- New function! This will change the camera view to whatever player is given for the function!
pcall(function() -- To make sure it doesn't throw an error.
spectateFrame.TextLabel.Text = tostring(playerSubject)
cam.CameraSubject = playerSubject.Character
end)
end
updatePlayerList() -- We'll update it right away, then when a player leaves/joins
game.Players.PlayerAdded:Connect(function(player)
updatePlayerList()
end)
game.Players.PlayerRemoving:Connect(function(player)
updatePlayerList(player)
end)
button.MouseButton1Click:Connect(function()
if openNow then
openNow = false
spectateFrame.Visible = true
position = 1 -- We're gonna set it to the first player in the table when they open up spectate!
updateCamera(playerList[1])
else
openNow = true
spectateFrame.Visible = false
updateCamera(game.Players.LocalPlayer) -- Adding it to close
end
end)
spectateFrame.LeftButton.MouseButton1Click:Connect(function()
position = position - 1
if position < 1 then
position = #playerList -- Change position to last on the list
end
updateCamera(playerList[position]) -- Changes camera to person on the list
end)
spectateFrame.RightButton.MouseButton1Click:Connect(function()
position = position + 1
if position > #playerList then
position = 1 -- Change position to last on the list
end
updateCamera(playerList[position]) -- Changes camera to person on the list
end)
spectateFrame.StopButton.MouseButton1Click:Connect(function()
openNow = true
spectateFrame.Visible = false
updateCamera(game.Players.LocalPlayer) -- Adding it to close so we can change back our camera!
end)