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

01local climbing = false
02 
03script.Parent.Touched:Connect(function(hit)
04 
05    if climbing == false then
06 
07        print("yes")
08 
09        if hit.Parent.Name == "HumanoidRootPart" or hit.Parent.Name == "LowerTrorso" or hit.Parent.Name == "UpperTorso" then
10            print("Yes")
11 
12            local zom = hit.Parent.Zombie
13            local anim = zom:LoadAnimation(script:FindFirstChildOfClass("Animation"))
14 
15            anim:Play()
View all 30 lines...

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

01local climbingAnimation = script.ClimbingAnimation --its better to just give the animation a name
02local touched --i'll bind and unbind the function instead of having a debounce
03 
04function onTouched(hit)
05    local ancestor = hit:FindFirstAncestorWhichIsA("Model") --find the character/zombie model
06    if ancestor and ancestor:FindFirstChild("Zombie") then --check if the ancestor exist and has a "Zombie" humanoid in it
07        touched:Disconnect() --unbind the function from the event "clear things a little for optimization i guess?"
08        local zombie = ancestor.Zombie --get the zombie humanoid
09        local track = zombie:LoadAnimation(climbingAnimation) --load the animation track
10        track.Looped = false --you can just toggle looping in the animation editor
11        track:Play() --play the animation
12        spawn(function()
13            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
14            touched = script.Parent.Touched:Connect(onTouched) --bind the function again
15        end)
16    end
17end
18 
19touched = 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