Script Exhaust Time with :GetPartsBoundInBox()

Hi, I’ve been trying to test out with GetPartsBoundInBoxes, but when I use this code to try to detect the character instead of the individual parts inside of the box, it instead timeouts the script.

I’ve tried changing the time the script waits until it prints, but either way it times it out. What do I do?

local cf = CFrame.new(20, 8, 0)
local size = Vector3.new(10, 10, 10)


local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.CanQuery = false
part.CanTouch = false
part.CFrame = cf
part.Size = size
part.Transparency = 0.5
part.Parent = game.Workspace

while true do
	
	
	local parts = game.Workspace:GetPartBoundsInBox(cf, size)
	
	
	local hitCharacters = {}
	for i, part in pairs(parts) do
	if part.Parent:FindFirstChildOfClass("Humanoid") and not table.find(hitCharacters, part.parent) then
		table.insert(hitCharacters, part.Parent)
	end
	print(hitCharacters)
	wait(0.5)
	end
end
1 Like

Just put the wait more at the top of the loop

while true do
	wait(0.5)


	local parts = game.Workspace:GetPartBoundsInBox(cf, size)


	local hitCharacters = {}
	for i, part in pairs(parts) do
		if part.Parent:FindFirstChildOfClass("Humanoid") and not table.find(hitCharacters, part.parent) then
			table.insert(hitCharacters, part.Parent)
		end
		print(hitCharacters)	
	end
end
2 Likes

Sorry for the late thanks, I had this not posted for some reason.

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