Hi. I Want to make a zombie climb over a small wall. This is a ServerScript inside a part, behind the wall
01 | local climbing = false |
02 |
03 | script.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() |
The script prints yes a lot of times, but nothing else. No error codes
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
01 | local climbingAnimation = script.ClimbingAnimation --its better to just give the animation a name |
02 | local touched --i'll bind and unbind the function instead of having a debounce |
03 |
04 | function 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 |
17 | end |
18 |
19 | touched = script.Parent.Touched:Connect(onTouched) --binds the function |