Hello, Full script is below thx already for any help
this script is for a sword so slash refers to the slashanimation, etc
my problem is that when i run the function DoDamage()[LINE 20] on line 49 or 63 the function never stops running, from that point if the sword just touches the dummy without actually doing the slash animation it already takes damage
how do i get the DoDamage() function to stop once it has hit the dummy?
if anything is unclear just comment thank you for the help
FULL SCRIPT:
script.Parent.Parent.Equipped:Connect(function() local char = script.Parent.Parent.Parent local hum = char.Humanoid local Slash1 = char.Humanoid:LoadAnimation(script.Parent.Slash1) local Slash2 = char.Humanoid:LoadAnimation(script.Parent.Slash2) idleanim = char.Animate.idle:WaitForChild('Animation1') toolnoneanim = char.Animate.toolnone:WaitForChild('ToolNoneAnim') local Stance = 'rbxassetid://2602051305' local Nothing = 'rbxassetid://2612295642' local DamagePoints = script.Parent.Parent.Damage.Value isHit = false damaging = false slashnum = 0 idleanim.AnimationId = Stance toolnoneanim.AnimationId = Nothing function DoDamage() -- the function if damaging == true then script.Parent.Parent.MeshPart.Touched:Connect(function(hit) if not isHit then isHit = true print('Hit!') local hithum = hit.Parent:FindFirstChild('Humanoid') if hithum then print('Found Humanoid') hithum:TakeDamage(DamagePoints) print(DamagePoints..' Damage dealt') end wait(0.5) isHit = false print(hithum.Health..'/'..hithum.MaxHealth..' '..hithum.Parent.Name..'!') end end) end end script.Parent.Parent.Activated:Connect(function() if not damaging then if slashnum == 0 then damaging = true Slash1:Play() print('1') DoDamage() -- starting the function wait(0.4) slashnum = 1 damaging = false end end end) script.Parent.Parent.Activated:Connect(function() if not damaging then if slashnum == 1 then damaging = true Slash2:Play() DoDamage() -- starting the function wait(0.4) slashnum = 0 damaging = false end end end) end)
You never disconnect the function from the .touched event, so it continues to call the function every time it is touched.
no you need to change the
wait(0.5) isHit = false
to true because as long as its false the function will run or put
is hit = false after if hithum then