Long story short I was testing my spectate script but when I click the previous buttion it works but When I click the next buttion it errors
When I tried to debug using prints it printed out this
yes1 - Client - Spectating Script:65
12:47:35.028 ▼ {
[1] = Player2,
[2] = Player1,
[3] = Player3
} - Client - Spectating Script:66
Script:
local Player = game.Players.LocalPlayer
local NextButtion = Player.PlayerGui.SpectatingUI.Frame:WaitForChild("Next")
local ProviousButtion = Player.PlayerGui.SpectatingUI.Frame:WaitForChild("Previous")
local GameInProgress = game.ReplicatedStorage:WaitForChild("GameInProgress_Repli")
local Camera = workspace.CurrentCamera
local Humanoid = Player.Character:WaitForChild("Humanoid")
local CloseButton = Player.PlayerGui.SpectatingUI:WaitForChild("ImageButton")
local PlayerSpecatingText = Player.PlayerGui.SpectatingUI.Frame:WaitForChild("TextLabel")
local OpenButtion = Player.PlayerGui.MenuButtons:WaitForChild("SpectatingButton")
local AvailableToSpectate = {}
OpenButtion.MouseButton1Click:Connect(function()
PlayerSpecatingText.Text = Player.Name
end)
NextButtion.MouseButton1Click:Connect(function()
if GameInProgress.Value == true then
Camera.CameraSubject = AvailableToSpectate[#AvailableToSpectate+1].Character.Humanoid
PlayerSpecatingText.Text = AvailableToSpectate[#AvailableToSpectate+1].Name
end
end)
CloseButton.MouseButton1Click:Connect(function()
Camera.CameraSubject = Player.Character.Humanoid
print("yes4")
end)
ProviousButtion.MouseButton1Click:Connect(function()
if GameInProgress.Value == true then
Camera.CameraSubject = AvailableToSpectate[#AvailableToSpectate-1].Character.Humanoid
PlayerSpecatingText.Text = AvailableToSpectate[#AvailableToSpectate-1].Name
end
end)
Humanoid.Died:Connect(function()
if table.find(AvailableToSpectate, Player.Name) and not Player:FindFirstChild("Student") and not Player:FindFirstChild("Baldi") then
for Index, V in pairs(AvailableToSpectate) do
if V == Player.Name then
table.remove(AvailableToSpectate, Index)
print("yes3")
end
end
end
end)
GameInProgress:GetPropertyChangedSignal("Value"):Connect(function()
if GameInProgress.Value == true then
for i, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("Student") then
table.insert(AvailableToSpectate,v)
elseif v:FindFirstChild("Baldi") then
table.insert(AvailableToSpectate,v)
end
print("yes1")
print(AvailableToSpectate)
end
end
end)