Run animation for the weapon tool does not function correctly when I try to use it while running

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am creating a local script for a weapon tool to trigger idle/walking animations after equipping the tool.

  2. What is the issue? Include screenshots / videos if possible!
    The walk animation functions properly if I equip the tool without any prior movement, but it doesn’t work correctly while running. Instead of replacing the idle animation, the walk animation causes the idle animation to keep triggering.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I attempted to use HumanoidStateChange to detect whether the player is running, but it did not work. Currently, I am using Humanoid.Running:Connect to trigger the idle/walk animation.

Code:
local userInput = game:GetService(‘UserInputService’)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local IdleAnimation
local MoveAnimation
local weaponEquip = true

script.Parent.Equipped:Connect(function()
character = player.Character or player.CharacterAdded:Wait()
humanoid = character:WaitForChild(“Humanoid”)
IdleAnimation = character:WaitForChild(“Humanoid”):LoadAnimation(script:WaitForChild(“IdleAnimation”))
MoveAnimation = character:WaitForChild(“Humanoid”):LoadAnimation(script:WaitForChild(“MoveAnimation”))

weaponEquip = true

IdleAnimation:Play()

humanoid.Running:Connect(function(movementSpeed)
    if weaponEquip == true then
        if movementSpeed > 0 then
            if not MoveAnimation.IsPlaying then
                IdleAnimation:Stop()
                MoveAnimation:Play()
            end
        else
            if MoveAnimation.IsPlaying then
                MoveAnimation:Stop()
                IdleAnimation:Play()
            end
        end
    end
end)

end)

script.Parent.Unequipped:Connect(function()
weaponEquip = false
IdleAnimation:Stop()
MoveAnimation:Stop()
end)

1 Like

try to see how “this post” animates his tools.

The animations work fine when the player is stationary and equips the tool, but the problem arises when the player is in motion and equips the tool. The issue is that the humanoid.running event doesn’t trigger to switch the idle animation to the walking animation. Regrettably, the solutions I have come across haven’t been effective.

1 Like

maybe put the equipped and unequipped events in the humanoid.running event

You need to change your animation priority.
See : AnimationTrack | Roblox Creator Documentation

When you load your MoveAnimation, you must set its AnimationPriority before calling :Play() in which case you can try changing the animation priority to Movement or a higher value.

1 Like

I have already set it up in the animation editor. However, I did try configuring it as you suggested, but it still doesn’t seem to work.
Code:

character = player.Character or player.CharacterAdded: Wait()
humanoid = character:WaitForChild(Humanoid)
IdleAnimation = character:WaitForChild(Humanoid): LoadAnimation(script:WaitForChild(IdleAnimation))
MoveAnimation = character:WaitForChild(Humanoid): LoadAnimation(script:WaitForChild(MoveAnimation))
MoveAnimation.Priority= Enum.AnimationPriority.Movement

I have resolved the issue by using this code. Do appreciate all help tho

if humanoid.MoveDirection.Magnitude > 0 then
	print("jump")
	
	MoveAnimation:Play()
	IdleAnimation:Stop()
else
	MoveAnimation:Stop()
	IdleAnimation:Play()
	
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.