Table detection not working

i have no idea what you’re really trying to achieve, but this is my best guess on what you want:

local function FindPlayer()
    for _,Player in pairs(Players:GetPlayers()) do
        if table.find(Array, Player.Name)  then--table.find is faster than ipairs/pairs
            return true
        end
    end
    return false
end

That should be the function, now for adding to the array:

local function UpdateArray()
	Array = {}
	for i,v in pairs(workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			        table.insert(Array,v.Name)
			print(v.Name.." added to table")
		end
	end
end

Perhaps this is what you wanted? Again, it would be useful to know what you want to actually achieve, such as more code, because right now, I can’t see any use for this system.

for _, Target in ipairs(GetPlayers) do

Won’t work, use

for _, Target in ipairs(Player.GetPlayers()) do
1 Like

TRY THIS:

local Array = {
"SomePlayersName" --Replace this with the player you want to target.
}

local Players = game:GetService('Players')
local playeradded = Players.PlayerAdded
for i,v in pairs(workspace:GetChildren()) do
	if v:FindFirstChild("Humanoid") then
		        table.insert(Array,v.Name)
		print(v.Name.." added to table")
	end
end
local function FindPlayerInArray()
	local GetPlayers = Players:GetPlayers() --Call the method so the player list will be updated
	for _, Target in ipairs(GetPlayers) do
		for _, Search in ipairs(Array) do
			if Target.Name:lower() == Search:lower() then --Comparing Names
				return true -- Player was found in the array
			end
		end
		return false -- Player was not found in the array
	end
	
end
while wait(1) do
	print(FindPlayerInArray()) -- true if found, false if not
	end

I switched to laptop; this is what im trying to say.

Maybe you should just loop trough the players in your UpdatePlayers function instead of any humanoid

local function FindPlayerInArray()
	for _, Target in ipairs(GetPlayers) do
		for _, Search in ipairs(Array) do
			if Target.Name:lower() == Search:lower() then
				print("player in array")
				for i,v in pairs(workspace:GetChildren()) do
					v.Name = "ok"
				return true
				end
			end
		end
	end
	print("didnt work")
		return false -- Player was not found in the array
end

What is the point of this? Why do you need it?

I was keeping true to the original code and what he posted. Like I said, I have no idea what this is being used for.

prints player in array honestly thank you all everybody who helped me in this post

This stops the loop try removing it.

Yeah, but why do you need it? What’s it used for?

Try explaining what you want to achieve in your code maybe I can help you.

Thats why I’m trying to say ;-;

im new to tables and i need this so i can create something with this and basically practice tables

for _, Target in ipairs(GetPlayers) do
		for _, Search in ipairs(Array) do
			if Target.Name:lower() == Search:lower() then

But why do you need to use this? What’s it’s practical purpose? This just checks if any player is in the array all players are added to.

so lets say i wanna make something with tables, this is pretty useful because i can use this to check if a player is in the table and if he is in that table i can execute a script. maybe some day im gonna make a minigame and i can use this to make it.

Well, the problem is you never specify what you want to look for, so it currently checks if any player is in that table.

i did specify that i need it do detect players in a table