Script skips over for loop code

I have been having this issue for weeks and I have no clue how to solve it. Basically the script skips over a particular for loop for no reason whatsoever and from testing with printing, it skips the whole of the for loop and only the for loop. The rest of the script is my take on a script that checks how far the player is from the AI and if it close enough, locks onto it. I know it’s dubious but I like learning scripting authentically and developing my own scripting style so unless the rest of the script directly causes the issue, just ignore the bad code for now(full code in file)


zomscrip.lua (1.4 KB)

Edit(screenshots of full script)


Have you checked the playtable variable? Seems to not have been mentioned in the post.

If its empty then the loop wont run. Make sure to constantly update this table such as :GetPlayers() or player added events.

Yes more times than u can count… I have printed it and there is always at least one player, which is me, yet it still does not run. and plus, it never actually gets to the in pairs loop, because everything in the for loop(that the in pairs loop is in) gets skipped

I’m guessing the “skip” appears because the script starts running before any of the players join the game.

Try removing the playtable variable at the start and instead, make the loop line be
for i, v in pairs(game.Players:GetPlayers()) do as it always gets the current player list, rather than the old player list at the start of the script.

Hope this helps!

2 Likes

Already checked that, on day 1 of the issue, did nothing. but I will try it the way ur doing it

thanks this actual worked and the rest of the script worked too, unexpectedly

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.