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.
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.
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
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.