What is a better way then just looping through everything in the workspace?

I want to know how I can prevent too many loops and make it so I don’t have to loop through the games workspace every time a player wants to slash for my magnitude hotbox system.


for i,v in pairs(game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") then
			local enemyHrp = v:FindFirstChild("HumanoidRootPart")
			if (RootPart.Position-enemyHrp.Position).Magnitude <= Range and v.Name ~= name then
				local hum = v:FindFirstChild("Humanoid")

put the script in StarterCharacterScripts instead.
the Player Character Will be The Parent

What about using Region3s?

you could add the players character to a folder in workspace and loop through the folder

I believe Region3 is mostly Deprecated, newer solution would be Overlap Params

if u want to find an specific object with no looping this is a method:

instace:FindFirstChild("idk", true)

Eh. Im not interested in raycasting or region3 or overlap params.

But you need to loop through all the player character instances in order to find if a character is in the hitbox

ok so instead of that use get players so u dont loop all workspace

GetPlayers() does not loop through the character objects, it only loops through player objects.

Can’t you grab the HRP and Enemy distance without looping through workspace, and if it isn’t in range you just return the script? (Bad english :D)

yeah but u dont understand the point bro u can loop by the player character with that method .__.

yeah that’s my problem. Im trying to figure a way to do that

Can you show a example of this?

try this

that actually can have some error with rbx core scripts

then the best way is as you said GetPlayers()

yeah of course

for i, plr in pairs(game.Players:GetPlayers()) do
       if plr.Character then
             local Hrp = plr.Character.HumanoidRootPart

Hmm… Let me try this new method.


Use the ‘CollectionService’ to tag humanoids.