I am working on a sword right now and everything is fine and perfect until I found out that my sword can only deal damage once and once only. I made another question on how to make the sword only deal damage when it was clicked and it's fixed, but now it created another problem, which is this. All the animation works, the main problem is just that it's only doing damage once. Please help!
Local Script
local CanAttack = true local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local idle = char:WaitForChild("Humanoid"):LoadAnimation(script.idle) local attack = char:WaitForChild("Humanoid"):LoadAnimation(script.attack) script.Parent.Equipped:Connect(function() idle:Play() script.Parent.Activated:Connect(function() if CanAttack then idle:Stop() attack:Play() CanAttack = false idle:Play() wait(1) attack:Stop() CanAttack = true script.Parent.CanDamage.Value = true end end) end) script.Parent.Unequipped:Connect(function() idle:Stop() end)
** Normal Script**
script.Parent.blade.Touched:Connect(function(p) if script.Parent.CanDamage.Value == true then p.Parent.Humanoid:TakeDamage(20) script.Parent.CanDamage.Value = false end end)
make the script like this (i think):
script.Parent.blade.Touched:Connect(function(p) if script.Parent.CanDamage.Value == true then script.Parent.CanDamage.Value = false p.Parent.Humanoid:TakeDamage(20 + math.random(1,20)) script.Parent.CanDamage.Value = true end end)
There was a CanDamage value blocked to make debounce so you can add some random number instead.
If this helped you, please mark this as the correct answer, or else comment below what error occurred in your output, Thanks :)