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
4 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:

local anim = script.Block

local function onHealthChanged()
    wait(0.5)
    anim:Play
end
0
btw is this local or server? Rdumb1 4 — 4y

2 answers

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

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

local npc = --your npc here
local anim = script.Block

local function onHealthChanged()
    wait(0.5)
    anim:Play()
end

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.

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

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

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://3410088748" -- animation ID

local animController = Instance.new("AnimationController", script.Parent)
local animTrack = animController:LoadAnimation(anim)




local function onHealthChanged()
    wait(0.5)
    animTrack:Play()
end

if your NPC does have Humanoid in it use this script

local char = script.Parent
local humanoid = char.Humanoid

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://3410088748" -- animation ID


local p = humanoid:LoadAnimation(anim)
p.Priority = Enum.AnimationPriority.Action

local function onHealthChanged()
    wait(0.5)
    p:Play()
end


--[[while wait(2) do
    onHealthChanged()
end]]

Answer this question