I'm creating an enemy were if you hit it, and wait a second, it would block, but since I'm new to scripting (blame my mind since I forget most of the stuff when watching tutorials and reading tutorials in the roblox wiki, rewatching(rereading) can be a pain but I still forget)
Basically if you hit the enemy(npc, not player) and wait a second, the enemy would block and play an animation (the blocking animation.) but nothing works.
script:
1 | local anim = script.Block |
2 |
3 | local function onHealthChanged() |
4 | wait( 0.5 ) |
5 | anim:Play |
6 | end |
idk if this will work if not sorry for wasting your time but here goes nothing:
1 | local npc = --your npc here |
2 | local anim = script.Block |
3 |
4 | local function onHealthChanged() |
5 | wait( 0.5 ) |
6 | anim:Play() |
7 | end |
8 |
9 | npc:WaitForChild( "Humanoid" ).HealthChanged:Connect(onHealthChanged) |
again sorry if it doesnt work but at least i tried
*Note that the npc variable must be an instance that is a parent to Humanoid.
If your NPC does not have Humanoid in it use this script
01 | local anim = Instance.new( "Animation" ) |
02 | anim.AnimationId = "rbxassetid://3410088748" -- animation ID |
03 |
04 | local animController = Instance.new( "AnimationController" , script.Parent) |
05 | local animTrack = animController:LoadAnimation(anim) |
06 |
07 |
08 |
09 |
10 | local function onHealthChanged() |
11 | wait( 0.5 ) |
12 | animTrack:Play() |
13 | end |
if your NPC does have Humanoid in it use this script
01 | local char = script.Parent |
02 | local humanoid = char.Humanoid |
03 |
04 | local anim = Instance.new( "Animation" ) |
05 | anim.AnimationId = "rbxassetid://3410088748" -- animation ID |
06 |
07 |
08 | local p = humanoid:LoadAnimation(anim) |
09 | p.Priority = Enum.AnimationPriority.Action |
10 |
11 | local function onHealthChanged() |
12 | wait( 0.5 ) |
13 | p:Play() |
14 | end |
15 |
16 |
17 | --[[while wait(2) do |
18 | onHealthChanged() |
19 | end]] |