so I made a script that makes an NPC punch when it gets close to the player & it is meant to damage them & I register the hit by testing for a collision with the NPC's hand but the problem is it doesn't always register & they barely do any damage. So is there any way to use CFrame or something to detect if the target is directly in front of the NPC?
here is the original script:
PunchHit = script.Parent.Parent.PunchHit
function onTouched(hit)
while PunchHit.Value == true do
local human = hit.Parent:findFirstChild("Humanoid")
if (human ~= nil) then
if script.Parent.Parent.Robot.Health > 0 then
human.Health = human.Health - 50 -- Change the amount to change the damage.
end
end
PunchHit.Value = false
end
end
script.Parent.Touched:connect(onTouched)
BTW 'PunchHit' is a boolean value that turns to true when the NPC plays the punch animation.
