Sword Running Animation not working

Hello! So I’m currently trying to make a combat system for an upcoming game and am trying to make the sword running system but for some reason it’s not working.

I have tried looking up videos and dev forum posts but none have been helpful.

Here is my code:


local Player = game.Players.LocalPlayer

local Char = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Char:WaitForChild("Humanoid")

local Anim = script.Parent.Run

local Track = Humanoid:LoadAnimation(Anim)

script.Parent.Equipped:Connect(function()
	
	Humanoid.Running:Connect(function()
		if Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
			Track:Play()
		else
			Track:Stop()
		end	
	end)
	
end)

This is a local script inside the sword.

what’s happening is that instead of playing the running animation it just plays the default tool run animation.

Sorry for the trouble and thanks for the help!

local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")

local Anim = script.Parent.Run
local Track = Humanoid:LoadAnimation(Anim)

local RunningFunc = nil

script.Parent.Equipped:Connect(function()
	RunningFunc = Humanoid.Running:Connect(function(Speed)
		if Speed > 5 then
print("Play")
			Track:Play()
		else
print("Stop")
			Track:Stop()
		end	
	end)
end)

script.Parent.Unequipped:Connect(function()
	pcall(function()
		RunningFunc:Disconnect()
		RunningFunc = nil
	end)
end)

try this maybe

That didn’t appear to work. The animation didn’t play but it printed. It also printed like 2 to 5 times every time I started and stopped running.

Sorry for the trouble.

Put this inside of the tool. Gives you a custom idle and run animation. (r15)

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer

repeat wait(1) until player.Character

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")
local sprintSpeed = 30
local walkSpeed = 16
local crouchSpeed = 10
local equipped = false

local animation = Instance.new("Animation")
animation.Name = "Idle"
animation.Parent = script.Parent
animation.AnimationId = "rbxassetid://8269791536"
local animtrack = humanoid:LoadAnimation(animation)

local runAnim = Instance.new("Animation")
runAnim.Name = "Sprint"
runAnim.Parent = script.Parent
runAnim.AnimationId = "rbxassetid://6932225442"
local runAnimTrack = humanoid:LoadAnimation(runAnim)

local function beginSprint(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local keycode = input.KeyCode
			if keycode == Enum.KeyCode.LeftShift and equipped then
				runAnimTrack:Play()
			end
		end
	end
end

local function endSprint(input, gameProcessed)
	if not gameProcessed then
		if input.UserInputType == Enum.UserInputType.Keyboard then
			local keycode = input.KeyCode
			if keycode == Enum.KeyCode.LeftShift then
				runAnimTrack:Stop()
			end
		end
	end
end

script.Parent.Equipped:Connect(function()
	if character.Humanoid.WalkSpeed == sprintSpeed then
		runAnimTrack:Play()
	else
		animtrack:Play()
	end
	
	equipped = true
end)

script.Parent.Unequipped:Connect(function()
	animtrack:Stop()
	runAnimTrack:Stop()
	equipped = false
end)


UIS.InputBegan:Connect(beginSprint)
UIS.InputEnded:Connect(endSprint)



I’m not trying to make a sprint animation. I’m trying to make just a normal run animation for when you are just walking around normally. Sorry if I wasn’t clear.

You’d probably be better off just using the default animation script for this one.

Playtest a blank game, copy the Animation script that’s inside your character, then paste it into the StarterCharacter folder of your actual game. That will replace the default animation script with the one in StarterCharacter, and you can edit it at your leisure.

If you want regular animations when no sword is equipped, then create a RemoteEvent that the server can fire to send a new set of animations to the client.

Then you can construct a listener in your newly created animation script, and it’ll look something like this:

game.ReplicatedStorage.Remotes.ChangeAnims.OnClientEvent:Connect(function(newSet)
	for name,id in pairs(newSet) do
		local holder = script:WaitForChild(name, 3)
		local anim = holder and holder:FindFirstChildWhichIsA("Animation")
		
		if anim then
			anim.AnimationId = "rbxassetid://"..id
		end
	end
	
	stopAllAnimations()
	onRunning(Torso.AssemblyLinearVelocity.Magnitude)
end)

-- In a Server Script
game.ReplicatedStorage.Remotes.ChangeAnims:FireClient(Player, {idle = 00000, run = 00000})

I’ve tried replacing the run animation in the animate script with my own but when I do that it just makes me glide for some reason.

Like this:

Are you using r15 or r6? If your gliding around then your using the wrong script.

Now that I think about it it is an R6 animation. That’s probably why. I didn’t realize it. Thanks for pointing that out!

I’ll make a new animation when I get the chance and get back to you.

No problem. Glad i could help. You can also search “R6 animation script” in the tool box and all kinds will pop up. Also make sure your game is in r6 mode. Or you can just change your humanoid to r15.

1 Like

Is the game published and owned by you?
if yes, is the animation you’re using owned by you?

Yes and Yes. I got it to semi work thanks to @AstroStudioz . The animation now plays but not quite correctly. It’s kind of meshing the default tool walking animation and mine together.