My code is supposed to detect how many players there are in-game, and then execute another for loop inside, that gets the descendants of a Model. The issue is the descendant for loop is only running once. I’ve tested this without the player for loop and it still only ran once.
-- Teleport players to StartPads
for a,b in pairs(PlayerService:GetPlayers()) do
for c,d in pairs(LoadedItems:GetDescendants()) do
print("got here")
if d.Name == "StartPad" then
print("got here 2")
local StartPads = {}
local HumanoidRoot = b.Character:WaitForChild("HumanoidRootPart")
table.insert(StartPads, d)
HumanoidRoot.CFrame = CFrame.new(StartPads[1].Position)
table.remove(StartPads, 1)
else
return
end
end
end
"got here" is only printing once. This is being tested with one player in-game.
In my entirety of scripting, I’ve never seen continue before in my life. Thanks! This will definitely help me a lot in the long run. Will save me a lot of time.
Sorry for the late reply, I was at dinner with my family.
In my experience with Python, using statements such as continue or break can become crutches to writing elegant code. Having continues or breaks can make debugging more difficult with large codebases, and can generally be avoided in most circumstances. Unless I’m misunderstanding your code here, continue will just bring you to the evaluation of the next iteration of your inner for loop if the else block is reached.
Removing the entire else block would give the same functionality because if the initial condition is false the next iteration will be run immediately after since there is no further code there.