Catching all the humanoids

H e l p

image
I did everything just like you said

Can I see the code plus coroutine doesn’t really reduces lag, but if your doing these type of loops looping through heaps of object, it is needed because it would get a script timeout, because it blocks other script. Like imagine if you had to multi task heaps of things at the same time, that’s basically what the computer does so that’s why it’s needed to have coroutine on these loops.

do you know what that error means?

nope, I have no clues what it means

Well

for _,Target in pairs(game.Workspace:Descendants()) do
     if Target:IsA("Humanoid") then
          local hum = Target
          print("Humanoids Found")
     end


not what he’s looking for, he want a way to reduce lag, unless I’m reading the code wrong or smth

How i get this “players” in a server side?

game.Players:GetPlayers() returns a table of every player in your game.

i need to put something else in that pairs how do i do it?

you mean a like this?

for i,v in pairs(game.Players:GetPlayers())do

end

No, it sure is wrong but it is the way to represent what I want

for i,v in pairs(game.Players:GetPlayers(), Workspace.Npcs:GetChildren())do

end

for i,v in pairs loops through tables. if you want something like that you’d have to create a table then add GetChildren() and GetPlayers() to that table. Also, GetPlayers() doesn’t return a table of their player models, it returns their player instance which UI is stored in.

so … what if i tell you i don’t know how to make tables…

theres the wiki page for it, it has way more info than I can really give you.

read a little and I would do like this

local Array = {game.Players:GetPlayers(), Workspace.Npcs:GetChildren()}

for i,v in pairs(Array)do

end

you’ve got the idea of it. but doing :GetPlayers() and :GetChildren() returns tables. so you just made a table of 2 tables. you’d have do 2 seperate for i,v loops and just add v to the array table.

local Array = game.Players:GetPlayers()

for i,v in pairs(Array)do

end

I need to add a

game:GetService("Workspace").Npcs:GetChildren()

in this for

you’d have to loop through that table and add it to a seperate table with table.insert().

it is very confusing for me, could you explain in more detail?