Help finding a better way?

do you guys think there’s a better way to do this?

there’s nothing wrong with it i just want to know if there’s a better way to do this.

-- hitdetection--
            local hit = workspace:GetPartBoundsInBox(GivenCFrame,SizeVector3,olp)
			
			local hitsomething = false
			
			for i,v in pairs(hit) do
				if v.Parent:FindFirstChild("Humanoid") then
					hitsomething = true
					
					break
				end
			end
--hitdetection--

so basically, im trying to find a humanoid using the table given by the “getpartsinbounds” thing, so that if it does find one it makes the bool into true. but i already have so many “for i loops” that i think im lagging cus of it (idk im probably just imagining it).

thank you! i appreciate it :slight_smile: :+1:

1 Like

I dont think you would lag by using loops, as long as you aren’t trying to spawn parts everytime a humanoid is detected I guess you are fine. This code looks decent aswell

2 Likes

oh well that’s very relieving. thank you

2 Likes

The performance is going to largely depend on how often you are running the hitdetection function. Other than that your implementation with the for loop is perfectly fine and optimized.

1 Like

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