Whats a Better way to continuously check for hitbox

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Is there a better way to check for what hit the hitbox

  2. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    So far I’m using a while true loop and a for loop inside to loop through hitboxquery to check if parts.parent is a humanoid

local function loopCheck(PartCFrame, PartSize, QueryParams)
	while task.wait(0.1) do
		local HitBoxQuery = workspace:GetPartBoundsInBox(PartCFrame, PartSize, QueryParams) 
		for index, parts in pairs(HitBoxQuery) do
			if parts.Parent:FindFirstChild("Humanoid") or parts.Parent.Parent:FindFirstChild("Humanoid") then 
				return parts.Parent
			end
			
			if tick() - LastHit > HITBOX_SPAWNDELAY then
				return
			end
		end
	end
end

Instead of a while loop try using runservice.HeartBeat

1 Like

Yes, Heartbeat would be preferable to a while task.wait() loop. Additionally, OverlapParams has a FilterDescendantsInstances property that can help with the humanoid checking.

2 Likes

ooooh thanks for the tip : ) ill definitely the additional params

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