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