Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Need help with finding if a hitbox is touching a part?

I have code that will generate a small part around the mouse, and I need to detect if this part touches any part named "HitBox". The problem is, "HitBox" is can collide false, so :GetTouchingParts() doesn't work. A sample of code:

local parts = deletePart:GetTouchingParts() -- Where it does not detect the hitbox
		local hitBox
		for i, part in pairs(parts) do
			
			print(part.Name)
			
			if part.Name == "HitBox" then
				hitBox = part
				break
			end
		end
		
		print("OI!")
		
		if hitBox then
			PlacementModule:Delete(hitBox.Parent)
		end
	end

Any help is appreciated, thanks!

2 comments

0

Use region3.

0

Could you give me a code sample?

1 answer

✓ Accepted answer

Even without CanCollide false :GetTouchingParts() will work. You forgot to add a Touch Interest. In order to add it, you just have to add a blank touched event.

deletePart.Touched:Connect(function() end)
local parts = deletePart:GetTouchingParts() -- Where it does not detect the hitbox
        local hitBox
        for i, part in pairs(parts) do

            print(part.Name)

            if part.Name == "HitBox" then
                hitBox = part
                break
            end
        end

        print("OI!")

        if hitBox then
            PlacementModule:Delete(hitBox.Parent)
        end
    end

1 comment

0

Sorry for the late response, it works like a charm!

This discussion is preserved as it was. New answers, comments, and votes are closed.