When equipped tool, walking animation will change

hey, yesterday I finished making a movement system and forgot I had speed coils. (the game has custom animations, including sprint animations.) I want to make it so when the tool is equipped, your walking animation will be changed to a run animation, and when unequipped, will change back.

having trouble finding any sources on this.

2 Likes

Use the tool.Equiped Function, then change your animation accordingly.

Try this

local tool = script.Parent
local RunAnimation = (Insert animation location here)

local player = game.Players.LocalPlayer.Character

local track
tool.Equipped:Connect(function()
    track = player.Humanoid:LoadAnimation(RunAnimation)
    track.Priority = Enum.AnimationPriority.Movement
    track:Play()
end)

tool.Unequipped:Connect(function()
    if track then
        track:Stop()
    end
end)

Doesn’t seem to play at all, confused about this.

Try messing around the the Priorities.

Did/done that already, tried messing with the Id area, locations, and the functions. nothing’s working.

Have you made sure your avatar is the exact same rig as your player? Like both are r6 or r15

Yes, infact here. This is my sprint script where if the player actually runs, it’ll play the animation perfectly. I want this to be modified so if the player equips the tool and begins to walk, they get the speed and the walk animation plays. (Speed coil.)

local UIS = game:GetService(‘UserInputService’)
local Player = game.Players.LocalPlayer
local Character = Player.Character

local Anim = Instance.new(‘Animation’)
Anim.AnimationId = ‘rbxassetid://10478382029’ – Change the ID to your own Animation, Otherwise put 0 for no Animation.
PlayAnim = Character.Humanoid:LoadAnimation(Anim)

local keyDown = false

UIS.InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then

	keyDown = true
	local animPlying = false

	while keyDown == true do
		wait(0.01)
		if Character.Humanoid.MoveDirection.Magnitude > 0 and keyDown == true then
			Character.Humanoid.WalkSpeed = 23 -- Change this to the running speed.
			if animPlying == false then
				animPlying = true
				PlayAnim:Play()
			end
		elseif Character.Humanoid.MoveDirection.Magnitude <= 0 and keyDown == true then
			Character.Humanoid.WalkSpeed = 23 -- Change this one too.
			if animPlying == true then
				animPlying = false
				PlayAnim:Stop()
			end
		end
	end
end

end)

UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then

	keyDown = false

	Character.Humanoid.WalkSpeed = 16
	PlayAnim:Stop()
end

end)

I don’t even know where to begin to modify it so it works with an “when equipped” instead of “key pressed”

local tool = script.Parent
local animation = tool:WaitForChild("Animation")

local player = game.Players.LocalPlayer
local char = player.Character

local loadAnimation = char.Humanoid:LoadAnimation(animation)

tool.Equipped:Connect(function()
	loadAnimation:Play()
end)

This worked for me so if it doesn’t work for you I’m not too sure man

Remember to set the Animation Priorities and have a handle.

I keep getting this, and it’s the exact way.

1 Like

How would I make it play only if the player moves? (Found a script that plays the animation when equipped, but always playing)

local tool = script.Parent
local anim = Instance.new(“Animation”)
local anim1 = Instance.new(“Animation”)
anim.Name = “IdleAnim”
anim.AnimationId = “rbxassetid://0” – Idle Animaton ID
anim1.Name = “WalkAnim”
anim1.AnimationId = “rbxassetid://10478382029”-- Equip Tool Animaton ID
local track
local track1
– When Tool Equipped
tool.Equipped:Connect(function()
track = script.Parent.Parent.Humanoid:LoadAnimation(anim)
track1 = script.Parent.Parent.Humanoid:LoadAnimation(anim1)
track.Priority = Enum.AnimationPriority.Movement
track1.Priority = Enum.AnimationPriority.Movement
track.Looped = true
track:Play()
track1:Play()
end)

– When Tool UnEqiopped
tool.Unequipped:Connect(function()
if track and track1 then
track:Stop()
track1:Stop()
end
end)

1 Like

You can use something like

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid") 

local walkAnim = script:WaitForChild("Animation")
local walkAnimTrack = humanoid.Animator:LoadAnimation(walkAnim)

humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if not walkAnimTrack.IsPlaying then
			walkAnimTrack:Play()
		end
	else
		if walkAnimTrack.IsPlaying then
			walkAnimTrack:Stop()
		end
	end
end)
1 Like

This just goes into a tool right?

And then implement this script into your tool script so it’d maybe look like

tool.Equipped:Connect(function()
	humanoid.Running:Connect(function(speed)
	if speed > 0 then
		if not walkAnimTrack.IsPlaying then
			walkAnimTrack:Play()
		end
	else
		if walkAnimTrack.IsPlaying then
			walkAnimTrack:Stop()
		end
	end
end)
end)

Little confused on where I would put the walkAnimTrack.

i wanna give up man, this si so difficult and i cant figure it out.

Oh crap I’m so sorry. local character should be local character = game.Players.LocalPlayer.Character

1 Like

I managed to achieve a run animation change by adjusting the roblox animation script following this post:

I adjusted mine so that it can play for R6, but if your game is R15 just copy from the thread I attached.

Heres a download so you can get a look at it:
RunningItemExample.rbxl (41.7 KB)