Making Tool Idle come back when you stop walking

With the help of dev forums and my own knowledge I have this script that will equip entire different animations when you hold a tool, when making this I noticed that when you stop walking you the idle for the sword won’t come back, instead it just gives regular animations. Is there a way for me to check if the player stopped walking, then check if there still holding the tool and make it select my idle? here is my code


local remoteEvent = ReplicatedStorage:WaitForChild("StoppedWalking")

remoteEvent:FireServer()

local plr = game:GetService("Players").LocalPlayer

local char = plr.Character or plr.CharacterAdded:Wait()

local h = char:WaitForChild("Humanoid")

local Idle = Instance.new("Animation")

Idle.AnimationId = "rbxassetid://7241020438"

local animIdle = h:LoadAnimation(Idle)

animIdle.Looped = true

animIdle.Priority = Enum.AnimationPriority.Idle

local Equip = Instance.new("Animation")

Equip.AnimationId = "rbxassetid://7245238821"

local animEquip = h:LoadAnimation(Equip)

animEquip.Looped = true

animEquip.Priority = Enum.AnimationPriority.Action

local DesEquip = Instance.new("Animation")

DesEquip.AnimationId = "rbxassetid://023032023"

local animDesEquip = h:LoadAnimation(DesEquip)

animDesEquip.Looped = true

animDesEquip.Priority = Enum.AnimationPriority.Action

local ChangeKey = Instance.new("Animation")

ChangeKey.AnimationId = "rbxassetid://023032023"

local animChgKey = h:LoadAnimation(ChangeKey)

animChgKey.Looped = true

animChgKey.Priority = Enum.AnimationPriority.Action

-------------------------------------------------

local Mouse = plr:GetMouse()

local Tool = script.Parent

Tool.Equipped:Connect(function()

animEquip:Play()

wait(0.2)

animEquip:Stop()

animIdle:Play()

end)

Tool.Unequipped:Connect(function()

animDesEquip:Play()

animDesEquip:Stop()

animIdle:Stop()

end)

h.Running:Connect(function(speed)

if speed > 0 then

animIdle:Stop()

end

end)
2 Likes

It would be much simpler and easier to just set Humanoid.WalkSpeed to 0 when the tool is equipped.

1 Like

Can you show a video of it happening??

Good point but doesn’t he want the player to be able to move while having the tool out?

I know what you’re saying. But in the end the result is the same. You walk, you can’t equip the tool… You don’t walk, you can use it happily.

For some reason, it will not load.

you can still use the tool, it just doesn’t have the SWORDS animations but puts my REGULAR animations

I have something for you here:

game.Workspace.Player.Humanoid.Running:Connect(function(speed)
    if speed > 0 then
        print("Player is running")
    else
        print("Player has stopped")
    end
end)

Read more

How would I direct it to the player? because game.Workspace.Player doesn’t work

That was an example…

You can refer to a player with game.Players.LocalPlayer if your using a LocalScript or game.Players:FindFirstChild(Player) from any script.

Ok so this should work, in your case I saw that you use a LocalScript.

local Char = game.Players.LocalPlayer.Character or player.CharacterAdded:Wait()

Char.Humanoid.Running:Connect(function(speed)
    if speed > 0 then
        print("Player is running")
    else
        print("Player has stopped")
    end
end)

This works, but how would I make it so it only brings back the idle if holding the sword