I have this spectator script that I made, but it is not very efficient, and I would like to improve it. How can I make it so instead of me subtracting numbers, it moves down the table as you click?
repeat wait() until game.Players.LocalPlayer.Character
local frame = script.Parent:WaitForChild('Frame')
local sub = frame:WaitForChild('Subtract')
local add = frame:WaitForChild('Add')
local name = frame:WaitForChild('Name')
local spectating = script.Parent:WaitForChild('SpectatingV')
local specButton = frame:WaitForChild('Spectating')
local fixSpecB = frame:WaitForChild('FixSpectate')
local db = false
local playerNO = 1
local players = game.Players:GetChildren()
if spectating.Value then
specButton.Text = 'Spectating: Yes'
elseif not spectating.Value then
specButton.Text = 'Spectating: No'
end
local addF = coroutine.wrap(function()
add.MouseButton1Click:connect(function()
if not db then
db = true
if playerNO < #players and #players > playerNO then
playerNO = playerNO + 1
elseif #players == playerNO then
--playerNO = playerNO - 1
else
print('no')
end
if spectating.Value then
game.workspace.CurrentCamera.CameraType = 'Custom'
game.Workspace.CurrentCamera.CameraSubject = game.workspace:FindFirstChild(players[playerNO].Name):FindFirstChild('Humanoid')
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
end
db = false
end
end)
end)
local subF = coroutine.wrap(function()
sub.MouseButton1Click:connect(function()
if not db then
db = true
if playerNO < #players and #players > playerNO then
playerNO = playerNO - 1
elseif playerNO == #players then
playerNO = playerNO - 1
else
print('no')
end
if spectating.Value then
game.workspace.CurrentCamera.CameraType = 'Custom'
game.workspace.CurrentCamera.CameraSubject = game.workspace:FindFirstChild(players[playerNO].Name):FindFirstChild('Humanoid')
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
end
db = false
end
end)
end)
local fixSpec = coroutine.wrap(function()
fixSpecB.MouseButton1Click:connect(function()
playerNO = 1
end)
end)
local specB = coroutine.wrap(function()
specButton.MouseButton1Click:connect(function()
if spectating.Value then
spectating.Value = false
specButton.Text = 'Spectating: No'
game.workspace.CurrentCamera.CameraType = 'Custom'
game.workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
elseif not spectating.Value then
spectating.Value = true
specButton.Text = 'Spectating: Yes'
game.workspace.CurrentCamera.CameraType = 'Custom'
game.workspace.CurrentCamera.CameraSubject = game.workspace:FindFirstChild(players[playerNO].Name):FindFirstChild('Humanoid')
game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic
end
end)
end)
local doSpec = coroutine.wrap(function()
while wait() do
if spectating.Value then
elseif not spectating.Value then
end
end
end)
local writeName = coroutine.wrap(function()
while wait() do
if playerNO == 0 then
playerNO = playerNO + 1
end
players = game.Players:GetChildren()
-- if players[playerNO].Name == game.Players.LocalPlayer.Character.Name then
-- table.remove(players, playerNO)
--end
print(playerNO)
name.Text = players[playerNO].Name
end
end)
addF()
subF()
specB()
doSpec()
writeName()
