Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help with iterating through a table?

local admins = {'Player1', 'Player2'}

for _, v in ipairs(admins) do
	print(_, admins)
	if player.Name == v then
		adminButton.Visible = true
	else 
		break
	end
end

When it prints, it prints some random letters and number in the output. I'm trying to go through the lists of admins, but it only seems to work for whoever is first in the table.

2 comments

0

what's adminButton, you never defined it

0

That doesn't matter in the code. The error is not the adminbutton, it's it not looping through the admins

1 answer

✓ Accepted answer

It prints random numbers because you are printing the "underscore" variable. "underscore" in your script is given the position of 'v' in the table 'admins'.

Also, your script only works for the first person in the table because you stop the loop using 'break' if player.Name is not equal to v (that is, the first value in the table: "Player1").

5 comments

0

The break only occurs if the players name is not the admin. The game only had 2 players, Player1 and Player2. As for it printing random numbers could you explain more??

0

Sorry, the website kinda screwed the formatting of my text. You are printing the value of the 'underscore' variable, which is given the position of 'v' in the table you are browsing.

0

Also, a little correction: the break only occurs if the player's name is not the first in the admin table. Remove the "else break end" and everything will be fine.

0

Thank you! works now. Is there anyway I can like break it, cause I don't want it looping forever, when it only needs to check when the player has joined

0

Your loop won't loop forever. It only loops once for each element in your table, comparing the current element to the player's name.

This discussion is preserved as it was. New answers, comments, and votes are closed.