It says "Animation1 is not a valid member of LocalScript" yet i put Animation1 Animation2 and Animation3 in the script. I put it in the local script itself so i dont know what happened any help just let me know. Thanks :)

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.Animation1, script.Animation2, script.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.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)

4 comments

2

try adding a waitforchild

0

yes try WaitForChild sometimes the script will load in faster than the children and that line will run and it will return nil because it hasn't loaded in yet

0

Yes that worked it solved the error but after 3 punches it doesnt work when pressing f. How to fix?

0

^^^