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

block script for enemy not functioning?

Asked by
Rdumb1 4
5 years ago

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:

1local anim = script.Block
2 
3local function onHealthChanged()
4    wait(0.5)
5    anim:Play
6end
0
btw is this local or server? Rdumb1 4 — 5y

2 answers

Log in to vote
0
Answered by
Lazarix9 245 Moderation Voter
5 years ago

idk if this will work if not sorry for wasting your time but here goes nothing:

1local npc = --your npc here
2local anim = script.Block
3 
4local function onHealthChanged()
5    wait(0.5)
6    anim:Play()
7end
8 
9npc: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.

Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

If your NPC does not have Humanoid in it use this script

01local anim = Instance.new("Animation")
02anim.AnimationId = "rbxassetid://3410088748" -- animation ID
03 
04local animController = Instance.new("AnimationController", script.Parent)
05local animTrack = animController:LoadAnimation(anim)
06 
07 
08 
09 
10local function onHealthChanged()
11    wait(0.5)
12    animTrack:Play()
13end

if your NPC does have Humanoid in it use this script

01local char = script.Parent
02local humanoid = char.Humanoid
03 
04local anim = Instance.new("Animation")
05anim.AnimationId = "rbxassetid://3410088748" -- animation ID
06 
07 
08local p = humanoid:LoadAnimation(anim)
09p.Priority = Enum.AnimationPriority.Action
10 
11local function onHealthChanged()
12    wait(0.5)
13    p:Play()
14end
15 
16 
17--[[while wait(2) do
18    onHealthChanged()
19end]]

Answer this question