Needing a performant but reliable way to get NearbyParts every frame

Problem: Calling GetPartBoundsInBox every frame for up to 20 players is not easy on performance.

Details: For my anticheat, I have to call GetPartBoundsInBox to get nearby parts within radius of the HumanoidRootPart. This way my anticheat doesn’t bother with BaseParts outside of the radius when checking for cheats like noclipping, flying, etc.

Tried solutions: So far I’ve tried scrapping GetPartBoundsInBox in general and just using Workspace:GetDescendants() and while this does work, I’m sure that if my game has thousands of parts this will become just as bad as my current function or possibly even worse.

I’ve also implemented performance saving features such as not checking for any possible cheating if the player is not moving and reusing the ‘nearby parts’ table if they haven’t moved ~4 studs. This has actually saved a heap of performance, but it still isn’t good enough.

NearbyParts = {Terrain}
			
			for _, BasePart in pairs(
				WorkspaceService:GetPartBoundsInBox(
					HumanoidRootPart.CFrame, 
					Vector3.new(10, 10, 10), 
					OverlapParams.new())
				) 
			do
				if 
					not BasePart.Parent:FindFirstChild("Humanoid")
					and BasePart.CanCollide == true 
				then
					table.insert(NearbyParts, BasePart)
				end
			end

There’s got to be a way I can do this every frame without Script Activity sky rocketting to 2-3%. I’ve done some digging on what script activity actually means, and I’ve heard that if it gets around 3-5% it can slow down chat or other features. Any clarification on that would be really helpful.

2 Likes