I have a spectate gui that is supposed to cycle through only players that have a value inside of them set to true, using a for loop to do this. Here's the script:
function clicked() local players = game.Players:GetChildren() local num = script.Parent.Parent.p local camera = game.Workspace.CurrentCamera local characterImageFormat='http://www.roblox.com/Thumbs/Avatar.ashx?x=352&y=352&format=png&userid=%d'; if players[2] == nil then local spgui = game.Players.LocalPlayer.PlayerGui.spectategui.Frame local players = game.Players:GetChildren() local camera = game.Workspace.CurrentCamera camera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid spgui.ImageLabel.Image = "" spgui.t.Text = "No players in the server." return end for a, players in ipairs(players) do if players.IsPlaying.Value == true then num.Value = num.Value + 1 if players[num.Value] == nil then -- This is where the script breaks num.Value = 1 if players[num.Value].Name == game.Players.LocalPlayer.Name then num.Value = num.Value + 1 camera.CameraSubject = players[num.Value].Character.Humanoid script.Parent.Parent.ImageLabel.Image = characterImageFormat:format(players[num.Value].userId) script.Parent.Parent.t.Text = players[num.Value].Name else camera.CameraSubject = players[num.Value].Character.Humanoid script.Parent.Parent.ImageLabel.Image = characterImageFormat:format(players[num.Value].userId) script.Parent.Parent.t.Text = players[num.Value].Name end else if players[num.Value].Name == game.Players.LocalPlayer.Name then num.Value = num.Value + 1 if players[num.Value] == nil then num.Value = 1 if players[num.Value].Name == game.Players.LocalPlayer.Name then num.Value = num.Value + 1 camera.CameraSubject = players[num.Value].Character.Humanoid script.Parent.Parent.ImageLabel.Image = characterImageFormat:format(players[num.Value].userId) script.Parent.Parent.t.Text = players[num.Value].Name else camera.CameraSubject = players[num.Value].Character.Humanoid script.Parent.Parent.ImageLabel.Image = characterImageFormat:format(players[num.Value].userId) script.Parent.Parent.t.Text = players[num.Value].Name end end else camera.CameraSubject = players[num.Value].Character.Humanoid script.Parent.Parent.ImageLabel.Image = characterImageFormat:format(players[num.Value].userId) script.Parent.Parent.t.Text = players[num.Value].Name end end end end end script.Parent.MouseButton1Down:connect(clicked)
The problem is that later on in the script, I want to target specific players inside a table (i.e. players[6]), but it instead treats it as a property, making the script break. I need to find out how to shorten a table inside a for loop AND keep it as a table so that using something like players[3] wouldn't break the script.