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

How to check if clicker is in the table?

I have a click detector and I want only the people (names of them) in the table to be able to click it.

First I gather all the people in my group and everyone with a specific rank. (No IDs yet)

Admins = {}

for i, v in pairs(game.Players:GetChildren())do
	if v:IsInGroup() and v.GetRankInGroup()then
		table.insert(Admins, v.Name)
	end
end

Then I tried to make a function to check if the clicker is in the table but then realized how do I do that? Hehe, help would be much appreciated! Thanks.

function onClick(click)
if click.Name == Admins then
end
end

2 answers

✓ Accepted answer

admins = {
	"Potatoe",
	"Potatoe2"
}

function check(name)
	lol = false
	for i,v in pairs(admins) do
		if v:lower() == name:lower() then
			lol = true
		end
end
return lol
end

function onClick(player)
if check(player.Name) then
	--put the things that happen if the players an admin
end
end

I reccomend you use a for statement to search within a table for the player that you want to check is in the table. Look below!

Admins = {}
for i, v in pairs(game.Players:GetChildren())do
	if v:IsInGroup() and v.GetRankInGroup()then
        table.insert(Admins, v.Name)
	end
end

function check(PlayerName)
	for index, name in pairs(Admins) do
		if name == PlayerName then
			return true
		end
	end
	return false
end

function onClick(player)
	if check(player.Name) then
    	print("Player is an admin!")
	end
end


The code above should check wether the player with that name is entered into the Admins table, and if they are, then "Player is an admin!" should get printed. If the player is not an admin, nothing should happen.

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