Help with animation scripting

I hope this is in the right section and I have searched but not been able to find any solutions to what I’m trying to do.

Hello! I have been trying for ages to get R6 animations to work. I made a shift to run script that works finally but I found that if the player stands still and presses shift the animation plays so they are running on the spot.

What I’m trying to do is make it so that the running animation wont work if they are not moving eliminating the bug of running on the spot.

Script used:

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

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 35
	local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://8315000604'
		PlayAnim = Character.Humanoid:LoadAnimation(Anim)
		PlayAnim:Play()
	end
 end)

 UIS.InputEnded:connect(function(input)
 	if input.KeyCode == Enum.KeyCode.LeftShift then
 		Character.Humanoid.WalkSpeed = 16
 		PlayAnim:Stop()
 	end
 end)

I have searched the Devforum and sources like Youtube but non give me any ideas for solutions. Any help even if a tutorial will be helpful :grinning:

Try using

Character.Humanoid.Animator:LoadAnimation(Anim)

Sorry I’m new to trying to script where about should I insert that?

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 35
	local Anim = Instance.new('Animation')
		Anim.AnimationId = 'rbxassetid://8315000604'
		PlayAnim = Character.Humanoid.Animator:LoadAnimation(Anim)
		PlayAnim:Play()
	end
 end)

Tried it but it still seems to play the animation when hold shift and not moving. Thanks for the reply tho :grinning:

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

Player.CharacterAdded:Connect(function(Character)
	local Anim = Instance.new("Animation", Character)
	Anim.AnimationId = ""
	local Track = Character:WaitForChild("Humanoid"):LoadAnimation(Anim)
	
	local Activation = false
	
	UIS.InputBegan:Connect(function(input)
		if input.KeyCode == Enum.KeyCode.LeftShift then
			if Activation == false then
				Track:Play()
				Activation = true
			else
				Track:Stop()
				Activation = false
			end
		end
	end)
end)

I misunderstood @puofz solution should work fine

My brain is frying. I inserted what you put but it doesn’t seem to want to shift to run anymore.

You need to load the animation track outside of the event.

local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character =script.Parent -- Depending where the script is can use script.Parent if child of CharacterScripts
local Animation = Instance.new("Animation")
Animation.AnimationId = 'rbxassetid://8315000604'
PlayAnim = Character.Humanoid:LoadAnimation(Animateon) -- Also note that you should use Animator:LoadAnimation instead as this methd is deprecated.
Animation.Parent = script -- If you want it to be accessed by other script too you need it to be in game.

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		Character.Humanoid.WalkSpeed = 35	
		PlayAnim:Play()
	end
 end)

 UIS.InputEnded:connect(function(input)
 	if input.KeyCode == Enum.KeyCode.LeftShift then
 		Character.Humanoid.WalkSpeed = 16
 		PlayAnim:Stop()
 	end
 end)

oh an run system? mb and ye i just knew that characteradded dont work also on client
i thought you just need a help for playing animations

local YourAnimation = "" -- Your run anim
local ShiftSpeed = 30 -- Speed will be added 
local OriginalSpeed = 16 -- Original speed

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

repeat
	wait()
until
Player.Character

local Character = Player.Character

local Activation = false

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift then
		if Activation == false then
			Character:WaitForChild("Humanoid").WalkSpeed = ShiftSpeed
			Character:WaitForChild("Animate").run:GetChildren()[1].AnimationId = YourAnimation -- your run anim
			Activation = true
		else
			Character:WaitForChild("Humanoid").WalkSpeed = OriginalSpeed
			Character:WaitForChild("Animate").run:GetChildren()[1].AnimationId = "http://www.roblox.com/asset/?id=180426354" -- This is the org of the r6 run anim
			Activation = false
		end
	end
end)
1 Like

That seemed to have worked thanks!