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

how would u use a table to check a players name?

is there anyway to use a table to check a players name like this:

local players = {"paper", "someone", "aLightBulb"}

game.Players.PlayerAdded:Connect(function(player)
	if player.Name == players then
		print("yes")
	end
end)

but that wouldnt work, is there anyway to do this using a table like an array or something

1 answer

✓ Accepted answer

Iteration of an array is very easy:

local players = {"paper", "someone", "aLightBulb"}
for _, player in pairs(players) do
	print(player) -- prints out "paper", "someone", "aLightBulb"
end

Now you merely check if the player name matches any of the table's values:

local players = {"paper", "someone", "aLightBulb", "Vulkarin"}

game.Players.PlayerAdded:Connect(function(player)
	local found = false
	for _, storedPlayer in pairs(players) do
		if player.Name == storedPlayer then
			print("yes")
			found = true
			break
		end
	end
	
	if not found then print("no") return end
end)

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