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
COMMUNITY QUESTION
How to fix mob attack animation wont work?
1 answer
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.
2 comments
0
THX
0
hmmm, that's the problem? not sure
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
Please consider indentation. It makes your code easier to read for yourself, but more importantly, for other people if you share it.