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

How to fix mob attack animation wont work?

Asked by 5 years ago
while true do
local p = game.Players:GetChildren()
for i = 1,#p do
if p[i].Character~=nil then
if p[i].Character:findFirstChild("Torso")~=nil then
if (p[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude < 5 then
script.Parent.Humanoid:LoadAnimation(script.Parent.Slash):Play()
end
end
end
end
wait(1)
end
0
Please consider indentation. It makes your code easier to read for yourself, but more importantly, for other people if you share it. BlueGrovyle 278 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

This line is wrong:

script.Parent.Humanoid:LoadAnimation(script.Parent.Slash):Play()

You should load animations before you play them, like so:

local Animation = script.Parent.Humanoid:LoadAnimation(script.Parent.Slash)

And now, you can load the animation and it will work:

Animation:Play()

Final script:

local Animation = script.Parent.Humanoid:LoadAnimation(script.Parent.Slash)
    while true do
    local p = game.Players:GetChildren()
    for i = 1,#p do
    if p[i].Character~=nil then
    if p[i].Character:findFirstChild("Torso")~=nil then
    if (p[i].Character.Torso.Position - script.Parent.Torso.Position).magnitude < 5 then
    Animation:Play()
    end
    end
    end
    end
    wait(1)
    end

This should work. However, you should use a different method of getting and chasing players, because this one might play the animation over and over each second, without it waiting to finish. A good example would be making the mob animate attacks when he's close enough, in a separate loop, instead of the same loop where he's actively hunting people.

0
THX dark_nineret -25 — 5y
0
hmmm, that's the problem? not sure starmaq 1290 — 5y
Ad

Answer this question