Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is the animation:Play() not working? *specific title*

Asked by
WoTrox 345 Moderation Voter
5 years ago

Hi. I Want to make a zombie climb over a small wall. This is a ServerScript inside a part, behind the wall

local climbing = false

script.Parent.Touched:Connect(function(hit)

    if climbing == false then

        print("yes")

        if hit.Parent.Name == "HumanoidRootPart" or hit.Parent.Name == "LowerTrorso" or hit.Parent.Name == "UpperTorso" then
            print("Yes")

            local zom = hit.Parent.Zombie
            local anim = zom:LoadAnimation(script:FindFirstChildOfClass("Animation"))

            anim:Play()
            anim.Looped = false
            climbing = true
            wait(2.2)
            climbing = false
            print("YES")

        end

    else

        print("no")

    end

end)

The script prints yes a lot of times, but nothing else. No error codes

1 answer

Log in to vote
1
Answered by
Is_Hunter 152
5 years ago

i don't really know what's the issue in here but i assume that the Zombie humanoid won't work unless it's in the zombie model so try doing that and here's my solution and try editing it as you please if something is wrong with it

local climbingAnimation = script.ClimbingAnimation --its better to just give the animation a name
local touched --i'll bind and unbind the function instead of having a debounce

function onTouched(hit)
    local ancestor = hit:FindFirstAncestorWhichIsA("Model") --find the character/zombie model
    if ancestor and ancestor:FindFirstChild("Zombie") then --check if the ancestor exist and has a "Zombie" humanoid in it
        touched:Disconnect() --unbind the function from the event "clear things a little for optimization i guess?"
        local zombie = ancestor.Zombie --get the zombie humanoid
        local track = zombie:LoadAnimation(climbingAnimation) --load the animation track
        track.Looped = false --you can just toggle looping in the animation editor
        track:Play() --play the animation
        spawn(function()
            wait(2.2) --i don't know what's the purpose of the cooldown but since you had it i don't want to mess with it
            touched = script.Parent.Touched:Connect(onTouched) --bind the function again
        end)
    end
end

touched = script.Parent.Touched:Connect(onTouched) --binds the function
0
THANKS YOU SO MUCH!! WoTrox 345 — 5y
0
(The 2.2 is the animation length, so if I want to run something after the animation, I can just insert there. Thank you again) WoTrox 345 — 5y
Ad

Answer this question