So, I have this Code that plays an animation based on the mouse direction. however once an animation is played once it seems to be stuck on rig and wont play again
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Mouse = Player:GetMouse()
local tool = script.Parent
local Animations = {
Up = Humanoid:LoadAnimation(script.Animations.Up),
Down = Humanoid:LoadAnimation(script.Animations.Down),
Left = Humanoid:LoadAnimation(script.Animations.Left),
Right = Humanoid:LoadAnimation(script.Animations.Right)
}
local function onActivated()
local startPosX, startPosY = Mouse.X, Mouse.Y
local threshold = 500
local function playAndReset(animation)
animation.Priority = Enum.AnimationPriority.Movement
animation.Looped = false
animation:Play()
animation.Stopped:Connect(function()
animation:Stop()
end)
end
tool.Activated:Connect(function()
startPosX, startPosY = Mouse.X, Mouse.Y
end)
tool.Deactivated:Connect(function()
local endPosX, endPosY = Mouse.X, Mouse.Y
local deltaX, deltaY = endPosX - startPosX, endPosY - startPosY
if math.abs(deltaX) > math.abs(deltaY) then
-- Horizontal movement is greater
if deltaX > 0 then
-- Mouse moved to the right
playAndReset(Animations.Right)
warn(1)
else
-- Mouse moved to the left
playAndReset(Animations.Left)
warn(2)
end
else
-- Vertical movement is greater
if deltaY > 0 then
-- Mouse moved down
playAndReset(Animations.Down)
warn(3)
else
-- Mouse moved up
playAndReset(Animations.Up)
warn(4)
end
end
end)
end
tool.Activated:Connect(onActivated)