Help with my spectator script?
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?
001 | repeat wait() until game.Players.LocalPlayer.Character |
003 | local frame = script.Parent:WaitForChild( 'Frame' ) |
004 | local sub = frame:WaitForChild( 'Subtract' ) |
005 | local add = frame:WaitForChild( 'Add' ) |
006 | local name = frame:WaitForChild( 'Name' ) |
007 | local spectating = script.Parent:WaitForChild( 'SpectatingV' ) |
008 | local specButton = frame:WaitForChild( 'Spectating' ) |
009 | local fixSpecB = frame:WaitForChild( 'FixSpectate' ) |
012 | local players = game.Players:GetChildren() |
013 | if spectating.Value then |
014 | specButton.Text = 'Spectating: Yes' |
015 | elseif not spectating.Value then |
016 | specButton.Text = 'Spectating: No' |
020 | local addF = coroutine.wrap( function () |
021 | add.MouseButton 1 Click:connect( function () |
024 | if playerNO < #players and #players > playerNO then |
025 | playerNO = playerNO + 1 |
026 | elseif #players = = playerNO then |
031 | if spectating.Value then |
032 | game.workspace.CurrentCamera.CameraType = 'Custom' |
033 | game.Workspace.CurrentCamera.CameraSubject = game.workspace:FindFirstChild(players [ playerNO ] .Name):FindFirstChild( 'Humanoid' ) |
034 | game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic |
040 | local subF = coroutine.wrap( function () |
041 | sub.MouseButton 1 Click:connect( function () |
044 | if playerNO < #players and #players > playerNO then |
045 | playerNO = playerNO - 1 |
046 | elseif playerNO = = #players then |
047 | playerNO = playerNO - 1 |
051 | if spectating.Value then |
052 | game.workspace.CurrentCamera.CameraType = 'Custom' |
053 | game.workspace.CurrentCamera.CameraSubject = game.workspace:FindFirstChild(players [ playerNO ] .Name):FindFirstChild( 'Humanoid' ) |
054 | game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic |
060 | local fixSpec = coroutine.wrap( function () |
061 | fixSpecB.MouseButton 1 Click:connect( function () |
065 | local specB = coroutine.wrap( function () |
066 | specButton.MouseButton 1 Click:connect( function () |
067 | if spectating.Value then |
068 | spectating.Value = false |
069 | specButton.Text = 'Spectating: No' |
070 | game.workspace.CurrentCamera.CameraType = 'Custom' |
071 | game.workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid |
072 | game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic |
073 | elseif not spectating.Value then |
074 | spectating.Value = true |
075 | specButton.Text = 'Spectating: Yes' |
076 | game.workspace.CurrentCamera.CameraType = 'Custom' |
077 | game.workspace.CurrentCamera.CameraSubject = game.workspace:FindFirstChild(players [ playerNO ] .Name):FindFirstChild( 'Humanoid' ) |
078 | game.Players.LocalPlayer.CameraMode = Enum.CameraMode.Classic |
082 | local doSpec = coroutine.wrap( function () |
084 | if spectating.Value then |
086 | elseif not spectating.Value then |
091 | local writeName = coroutine.wrap( function () |
093 | if playerNO = = 0 then |
094 | playerNO = playerNO + 1 |
096 | players = game.Players:GetChildren() |
101 | name.Text = players [ playerNO ] .Name |