Table detection not working

its been a week please help me make it detect the player

local Array = {

}

local Players = game:GetService('Players')
local playeradded = Players.PlayerAdded
local GetPlayers = Players:GetPlayers()
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()
	
	for _, Target in ipairs(GetPlayers) do
		for _, Search in ipairs(Array) do
			if Target.Name:lower() == Search:lower() then
				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

also theres a few lines at the bottom.
what i am trying to do is make it so it prints when it detects a player, and ive been failing to do this for a week now please help.

Make sure it’s one line, and the main source of your problem is probably that you didn’t call the function.

At the bottom i did

while wait(1) do
	print(FindPlayerInArray()) -- true if found, false if not
	end

The table being defined in 3 lines isn’t the issue here. It’s completely valid in Lua and the majority of other languages.

@vovcher Are you adding the player to the table when they join? That may be the problem.

This leads me to believe that you do but you didn’t provide the part where you actually connected a function to the playeradded scriptsignal.

At the first for-loop on the FindPlayerInArray() function do for _, Target in ipairs(Players:GetPlayers()) do
You should frequently call Players:GetPlayers() so you get an updated array of the players. You should not assign them in a variable.

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

that isnt working also tried using game.players.playeradded and inserting them into the table that didnt work aswell

I have no idea what your issue is then. Try looping though the table and printing all the values, as well as checking the output for errors if you haven’t already.

this loops it

while wait(1) do
	print(FindPlayerInArray()) -- true if found, false if not
	end

nothing in the output because it turns out false

Try putting some plr name into the ARRAY

does it not do it already? ive been told it loops it.

you see i tried that aswell turned out false

 local GetPlayers = Players:GetPlayers()

This won’t work, you are assigning GetPlayers the return value of Players:GetPlayers()

for i,v in pairs(workspace:GetChildren()) do
if v:FindFirstChild("Humanoid") then

Why? This adds any humanoid’s name to the table.

You should also add the player from PlayerAdded to the table.

No? 30 charatcndjsbsjsbdbsjsbdn

tried adding by using playeradded and it didnt work

Show the code you used for that

Or try adding the GetPlayers variable into the for loop at the function.

Won’t help, the GetPlayers variable is never updated except at the start when it is first assigned

game.Players.PlayerAdded:Connect(function(plr)
	table.insert(Array,plr.Name)
	end)
local Array = {"ok","ys","epicgamer","ok"
}
local Players = game:GetService('Players')
local GetPlayers = Players:GetPlayers()
local random = math.random(1,#Array)
game.Players.PlayerAdded:Connect(function(plr)
	table.insert(Array,plr.Name)
	end)
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

while wait(1) do
	FindPlayerInArray()
	print(table[random])
end

local function FindPlayerInArray()

for _, Target in ipairs(GetPlayers) do
	for _, Search in ipairs(Array) do

What is this supposed to do? You don’t specify what you want to search for?

it searches for players from what ive been told