GetTouchingParts ignoring something

I want the npcs able to damage a generator which has Humanoid

For some reason it seems like the GetTouchingParts just doesnt include generator even when i saw the npcs hitting it

			local connection
			task.spawn(function()
				-- Play anticipation sound
				task.delay(settings.BeforeSlashSound, function()
					Utils.playSlashSound(settings, model)
				end)

				-- Wait for anticipation time
				task.wait(settings.TimeToParry[state.combo])
				blade.CanTouch = true
				local hitCache = {}
				local par = false
				local hit = false

				connection = RunService.Heartbeat:Connect(function()
					if not state.attacking then return end -- stop checking if attack finished

					-- Get all parts overlapping the blade
					local touchingParts = blade:GetTouchingParts()
					for _, part in touchingParts do
						if part:FindFirstChild("p") then
							print("hit target")
						end
						local char = part:FindFirstAncestorOfClass("Model")

						if not char or not char:FindFirstChild("Humanoid") then continue end
						
						if hitCache[char] then continue end
						hitCache[char] = true
						

						local targetHumanoid = char:FindFirstChild("Humanoid")
						local blee = true
						if helper and char ~= owner.Character then
							blee = false
						end

						if not blee then continue end
						

						local root = char:FindFirstChild("HumanoidRootPart")
						local toNpc = (model.PrimaryPart.Position - root.Position).Unit
						local facingDot = root.CFrame.LookVector:Dot(toNpc)
						local parryThreshold = 0.4
						local blockThreshold = 0.4
						if char:FindFirstChild("Block") and char.Block.Value then
							if char:FindFirstChild("Parry") and char.Parry.Value and facingDot > parryThreshold and not par and not hit then
								-- Successful parry
								Combat.Parried(state, model, blade, target, root, state.hitConnection, humanoid, etype, track)
								par = true
							elseif facingDot > blockThreshold then
								-- Successful block
								Combat.Blocked(model, blade, root, target)
							else
								-- Player facing away, cannot block or parry
								local didHit = Combat.Damage(etype, targetHumanoid, char, part, settings)
								if didHit then hit = true end
							end
						else
							-- No block, apply damage
							local didHit = Combat.Damage(etype, targetHumanoid, char, part, settings)
							if didHit then hit = true end
						end

					end
				end)

			end)

the generator:

It never prints hit target

2 Likes

Is the CanCollide, CanQuery etc. of the HumanoidRootPart enabled?

1 Like


CanCollide is disabled since its just a hitbox

1 Like

Is CanTouch on the blade enabled?
Try this to see why this function isn’t working:

				connection = RunService.Heartbeat:Connect(function()
                    print(state.attacking)
					if not state.attacking then return end -- stop checking if attack finished

If the print doesn’t show up then the function isn’t being called so you have to look into that section of code.
prints ahead of a check with the variables used in the check will help you troubleshoot sections of your code.

1 Like

i dont think its that, it works perfectly on players, only the generator is an exception and yes the CanTouch is enabled.

1 Like

Try it anyway. It’ll tell you if it’s working or not.
The reason people have issues with troubleshooting is they focus on one thing, and don’t look at anything else.

1 Like

it alway’s prints true, im more of confused why isnt it included in the touching parts list at all even if they clearly are hitting it.

1 Like

I see you’re setting blade.CanTouch to true in the script. Maybe there’s a bit of lag there.

Select blade during testing to watch the Properties to see if it’s actually changing at the right time.

Try setting it to true manually and – any point in the script where it changes it to false to see if that makes a difference.

or

					local touchingParts = blade:GetTouchingParts()
					for _, part in touchingParts do
                        print(part.Name)  -- to see what's actually touching
1 Like

Can you try

for _, part in touchingParts do
  if part.Name == "p" then

  end
end

Is at least one of the 2 Parts (either the Part calling the method or the part you want to detect) unanchored? Pretty sure if neither are unanchored then they are physically unable to touch

Is the parts touching blade, a child or a descendant in a model ? Your Variable for touching parts is:

local touchingParts = blade:GetTouchingParts()

So is “p” a direct part touching the blade, or is it inside of a part that is touching blade.

If the part is in a model, the one your trying to recognize as touching the blade, then you should iterate through a model instead with something like this:

local touchingParts = blade:GetTouchingParts()

for _, part in touchingParts do   
    local model = part:FindFirstAncestorOfClass("Model")
    if model and model:FindFirstChild("p") then
        print("hit target")        
    end
end

i did this, but it wasnt printing the gen’s hitbox even when they were hitting it.

yes, the blade is welded, but its unanchored.

like i showed in my post its inside the generators hitbox, its ProximityPrompt, just used it to not have output clogged with tons of outputs.

i was doing that too, but with the name of the model instead.

is “p” the thing you want recognized as touching the blade ? It won’t work with a Proximity Prompt. GetTouchingParts()

A Proximity Prompt won’t be recognized in the GetTouchingParts(), because its not a part.

Maybe do something like this:

local function findPrompt(part)
    local prompt = part:FindFirstChild("ProximityPrompt")
    if prompt then
        print("Found a ProximityPrompt in part: " .. part.Name)
    end
end

I solved this by using getpartsinpart instead.

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