NPC damaged on touch with client player

Hello! I need help with making a script to put inside an enemy.

I have a hitbox called “slashHitbox” that appears in the humanoidrootpart of the player when the player uses a slash attack. I need the enemy to take damage upon touching this slashHitbox, as well as only take damage when it is the local player’s box.

I already tried an onTouched event, as well as test if the part the enemy was touching was inside the local player, however, the script never sensed the hitbox.
I also need debounce, so the enemy has a cooldown before taking damage again.

if you need additional info feel free to ask.
Thanks!

1 Like

whats your code (30 c hara cter s)

2 Likes

Well I scrapped it because I thought there might be a better way to do it but I assume it was this:

local  plyrserv = game:GetService("Players")
local character = plyrserv.LocalPlayer.Character

function onTouched(hit)
if hit.Name == "SlashHitbox" then
 if hit.Parent == Character.HumanoidRootPart then
  script.Parent.Humanoid.Health = script.Parent.Humanoid.Health - 25.5
 end
end
end
script.Parent.Touched:connect(onTouched)

I wrote this all in DevForum but I assume it doesn’t have syntax errors. This is a local script btw
edit: I forgot a few things lol

1 Like

I’m thinking it could be thinking the part isnt the local player somehow.

1 Like