Problem with tool running animation

  1. I want the running animation to play only when the player is running and has a tool equipped

  2. I looked for tutorials on youtube and developer hub, but none of the scripts worked or they were glitching out

local Sword = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
local Animate = Character:WaitForChild("Animate")

Sword.Equipped:Connect(function()

	Animate.run.RunAnim.AnimationId = "rbxassetid://15144877556"

end)

Sword.Unequipped:Connect(function()

	Animate.run.RunAnim.AnimationId = "rbxassetid://913376220"

end)

The animation id changes, but it doesn’t change the animation in-game.

3 Likes

Try this:

local Sword = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")

local runAnimationId = "rbxassetid://15144877556"

local isRunning = false

local function playRunningAnimation()
    Animate.run.RunAnim.AnimationId = runAnimationId
end

local function stopRunningAnimation()
    Animate.run.RunAnim.AnimationId = ""
end

local function checkRunning()
    if Humanoid:GetState() == Enum.HumanoidStateType.Running then
        if not isRunning then
            isRunning = true
            playRunningAnimation()
        end
    else
        if isRunning then
            isRunning = false
            stopRunningAnimation()
        end
    end
end

Sword.Equipped:Connect(function()
    checkRunning()
end)

Sword.Unequipped:Connect(function()
    if isRunning then
        isRunning = false
        stopRunningAnimation()
    end
end)

Character:WaitForChild("Humanoid").Running:Connect(checkRunning)
2 Likes

I tried the code,
animation played when the tool wasnt equipped.
I added a line of code that detects if the tool is equipped, but it doesn’t update when you equip the tool while running.

local Sword = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Animate = Character:WaitForChild("Animate")
local runAnimationId = "rbxassetid://15144877556"

local isRunning = false

local function playRunningAnimation()
	Animate.run.RunAnim.AnimationId = runAnimationId
end

local function stopRunningAnimation()
	Animate.run.RunAnim.AnimationId = "rbxassetid://913376220"
end

local function checkRunning()
	if Humanoid:GetState() == Enum.HumanoidStateType.Running then
		if not isRunning then
			if Character:WaitForChild("Sword") then -- this is what i added
				isRunning = true
			playRunningAnimation()
			end	
		end
	else
		if isRunning then
			if Character:WaitForChild("Sword") then -- this is what i added
					isRunning = false
			stopRunningAnimation()
			end
		end
	end
end

Sword.Equipped:Connect(function()
	checkRunning()
end)

Sword.Unequipped:Connect(function()
	if isRunning then
		isRunning = false
		stopRunningAnimation()
	end
end)

Character:WaitForChild("Humanoid").Running:Connect(checkRunning)
1 Like

So did the code work? I hope it did.

It works slightly, because when u equip the tool while running the animation doesn’t change

What would you like me to change? Im all ears :ear:

For some reason when i checked the script today, it all stopped working

You mightave changed something accidentally, or Roblox just did that.