so im making a npc system where when the npc hits you it deals 15 damage then pauses for 2 seconds being unable to deal damage or move but for some reason the hitbox i made that stays on the npc the whole time i just turn the cantouch on and off keeps increasing its damage by 10 every hit and i didn’t add that, is there any reason why this would happen?
Its going to be hard to help you without any code to look at, but it sounds like each time you set CanTouch back to true you are connecting another Touched event so then multiple events are being fired each successive collision.
i think that might be happening, how would i fix this without making new hitboxes each hit?
I made it so when you touch the part it deals damage and turns off can touch then after 2 seconds turns it back on.
hitbox.Touched:Connect(function(hit)
if hit.Name == "HumanoidRootPart" or hit.Name == "Right Leg" or hit.Name == "Left Leg" and hit.Name ~= Argument2.Name then
local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://139352387849831"
local animation = Argument2.Humanoid:LoadAnimation(anim)
animation:Play()
Path:Stop(Goal)
spawn(function()
pause = true
hitbox.CanTouch = false
wait(2)
pause = false
hitbox.CanTouch = true
end)
if hit.Parent.Humanoid.Health <= 15 then
hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - 1
workspace.Time.Value += 34
local BV2 = Instance.new("BodyVelocity")
BV2.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
BV2.Velocity = plr.Character.HumanoidRootPart.CFrame.LookVector * 40
BV2.Parent = hit
game:GetService("Debris"):AddItem(BV2,0.1)
hit.Parent.Humanoid.Health -= 15
local hitplr = game.Players:GetPlayerFromCharacter(hit.Parent)
hitplr.leaderstats.Rage.Value += 1
wait(1)
hit.Parent.survivor.Value = false
else
hit.Parent.Humanoid.Health -= 15
end
wait(0.01)
end
end)