Detecting humanoids.... different

so what i actually wanna know is that, is there even a more optimized way on
detecting nearby humanoids? like no performance huge drop or server lags
because the humanoid detection system i’ve been creating are laggy. i don’t know how anime fighting simulator x made theirs not laggy but i wanna know something like that how to create im not asking for a code im just asking how would i be able to create such humanoid detection system like AFSX.

the mob moves around and when there’s an enemy near it’ll go to the nearest target and starts attacking, i made one but when there is 10 of mobs it pretty much lags i don’t know why but i’d like to know how to make out. either like AFSX or BLOX FRUITS!

5 Likes

Could we see your code to figure out why its lagging?

4 Likes

it just lags when there’s a total of 10 mobs.
here’s an example of my code:

– server

local function getnearestentity()
for i,v in pairs(workspace:GetDescendants()) do
-- stuff then do return if its the perfect target.
end
end
while script do
local mob = getnearestentity()
-- some function of attacking
task.wait(0.1)
end
2 Likes

i’ve also tried workspace:GetPartsInPart and it was worse than i expected not gonna lie.

2 Likes

That alone shouldn’t be lagging maybe it’s because of your target code or attack code.

2 Likes

my workspace have 5K+ parts does that affect? the for i,v loop?
19k instances in total.

1 Like

Oh right, why don’t you just loop over the 10 mobs instead of the ENTIRE workspace?

1 Like

Store all your entities in a folder and loop over the folder

1 Like

i’m also detecting the players how would i do that?

1 Like

Loop over Players:GetPlayers() and get their character through that

1 Like

i’ve also seen the blox fruits devs not storing those in a single folder

1 Like

In that case use Tags. Add a tag called “Entity” to all of your npcs/players and then loop over CollectionService:GetTagged("Entity")

2 Likes

i’ve tried something like that using region3 im wondering why it does not work?

–// MODULE

–// SERVER

1 Like

you guys got any solution for this?

thanks, this kinda helped but one more question.
does it lag when there is around 20+ mobs like im going to loop through using collectionservice with entities tagged like that? only humanoid tho.

Luau is pretty fast, so I expect it can even loop through 500+ entities with no performance overhead, considering that you don’t perform any heavylifting calculations or yield during iterations.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.