Hello I’am working on making a method for damage output in my game.
I’m trying to make it so that if the hitbox on the sword, comes in contact with the EnemyHurtBox of the npc, it will print into the output as “Strucked”
But it does not seem to be working as it does not show up in the output
print("Hello world!")
local HitBox = script.Parent
local debounce = false
HitBox.Touched:Connect(function(Hit)
if debounce then return end
debounce = not debounce
if Hit.Parent:FindFirstChild("WeaponHurtBox") then
print("Strucked")
end
end)
Here is my script that I have inside the EnemyHurtBox. I have tried a lot of methods that i could find and none of them seem to work.
You aren’t resetting your debounce. At the end of the if statement, put debounce = false
if debounce then return end isn’t necessary. Just change the second if statement to if debounce == false and Hit.Parent:FindFirstChild("WeaponHurtBox") then and remove if debounce then return end
debounce = not debounce works, but I usually use debounce = true (Optional revision.)
Revised Script:
local HitBox = script.Parent --defines HitBox
HitBox.Touched:Connect(function(Hit) --BasePart.Touched event
if Debounce == false and Hit.Parent:FindFirstChild("WeaponHurtBox") then --Makes sure debounce is false and Hit.Parent has a WeaponHurtBox.
Debounce = true --Sets debounce to true so the touched event doesn't spam.
print("Strucked")
--do extra stuff
end
end)