Hello.
I have recently been playing around with a spectate gui, and I've run into an issue where the GUI only spectates one person in the server, and yourself only. Everything else works, however for some reasons this specific issue about not being able to spectate everybody ingame doesn't work. I'm unsure why this happens and would like some help.
Here's my script:
local Camera = workspace.CurrentCamera
local UI = script.Parent
local Players = game:GetService("Players")
local Debounce = false
local SpectateFrame = UI.SpectateHandler
local Title = SpectateFrame.Title
local PreviousButton = SpectateFrame.Previous
local NextButton = SpectateFrame.Next
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpectateRemote = ReplicatedStorage:WaitForChild("Spectate")
local function GetIngamePlayers()
for _, Player in pairs(Players:GetPlayers())do
if Player.Name == Title.Text then
return;
end
end
end
local function EnableSpectate()
SpectateFrame.Visible = true
pcall(function()
Title.Text = Players:GetPlayerFromCharacter(Camera.CameraSubject.Parent).Name
end)
end
SpectateRemote.OnClientEvent:Connect(EnableSpectate)
NextButton.MouseButton1Click:Connect(function()
wait(0.1)
if not (Debounce) then
Debounce = true
local Players = Players:GetPlayers()
local GetPlayers = GetIngamePlayers()
if not pcall(function()
Camera.CameraSubject = Players[GetPlayers - 1].Character.Humanoid
end)
then
Camera.CameraSubject = Players[#Players].Character.Humanoid
end
pcall(function()
Title.Text = Players[#Players].Name
end)
wait(0.1)
Debounce = false
end
end)
PreviousButton.MouseButton1Click:Connect(function()
wait(0.1)
if not (Debounce) then
Debounce = true
local Players = Players:GetPlayers()
local GetPlayers = GetIngamePlayers()
if not pcall(function()
Camera.CameraSubject = Players[GetPlayers + 1].Character.Humanoid
end) then
Camera.CameraSubject = Players[1].Character.Humanoid
end
pcall(function()
Title.Text = Players[1].Name
end)
wait(0.1)
Debounce = false
end
end)
Do keep in mind that this is definetly not the best script out there to do this, and there are definetly alot better ways to do this, and I'm still experimenting!
Thanks
