Can anyone help with my script because no matter what order I press f in , after three punches it stops working and no animations play afterwards.
local CanDoDmg = true -- If the player can do damage
local Keybind = "f"
local dmg = 20 -- How much damage the player takes
local punch_level = 0
local punch_animations = {script:WaitForChild("Animation1"), script:WaitForChild("Animation2"), script:WaitForChild("Animation3")}
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
mouse.KeyDown:Connect(function(key)
if key == Keybind then
if punch_level < 3 then
punch_level += 1 -- increase punch level, unless it's already the maximum
else
-- Abort the punch, because we don't have a 4th animation.
-- If you'd like it do something else, please say so in a comment.
return
end
local anim = script.Parent.Humanoid:LoadAnimation(punch_animations[punch_level])
anim:Play()
-- Removed a wait() here
script.Parent:WaitForChild("RightHand").Touched:connect(function(hit)
if hit.Parent.Humanoid and CanDoDmg == true then
hit.Parent.Humanoid:TakeDamage(dmg)
CanDoDmg = false
wait(1)
CanDoDmg = true
end
end)
local saved_punch_level = punch_level
wait(0.5)
if punch_level == saved_punch_level then
-- This code is only executed if the player hasn't initiated another punch.
punch_level = 0
end
end
end)

2 comments
it says in one of the comments, "Abort the punch, because we don't have a 4th animation." which means you can only do 3 punches, try removing the else
Thanks that works but after three presses it just plays the last animation every time you press f no matter what punch level you are?