I’m creating an attack for my NPC but for some it’s playing the wrong animation. When it prints “Choosing: Slam Attack” it plays the “Swing Punch” animation. It works fine in the beginning where it plays each of the correct animations once but after that it only performs one of the animation when the print says the other animation name.
local function ChooseAttack()
if choice == 1 then
currentAnim = SlamAttackAnim
choice = 2
else
currentAnim = SwingPunchAnim
choice = 1
end
currentAnim:Play()
end
local function Attack()
if not Attacking then
Attacking = true
ChooseAttack()
print("Choosing: "..tostring(currentAnim.Name))
coroutine.wrap(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local Player_Position = Player.Character.HumanoidRootPart.Position
local Player_Humanoid = Player.Character.Humanoid
local Golem_Position = Golem.Body.Position
if (Player_Position - Golem_Position).Magnitude <= 20 then
wait(currentAnim.Length / 2.5)
Player_Humanoid:TakeDamage(10)
end
end
end)()
currentAnim.Stopped:Connect(function()
Attacking = false
end)
end
end
if choice == 1 then
currentAnim = SlamAttackAnim
currentAnim:Play()
choice = 2
end
if choice == 2 then
currentAnim = SwingPunchAnim
currentAnim:Play()
choice = 1
end
So I figured out the issue. The reason that it kept playing the animation was because the swing or slam punch anim was looped. I tried setting AnimTrack.Looped = false for both in the beginning of the script but it seems it’s likely a bug from Roblox as I had to manually set the looped property to false in the animation editor. Thank you for your help though. I’ll mark yours as a solution.