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)
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.
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.
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
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
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