Sprinting animation won't stop playing after letting go of shift

I have a sprinting system that works fine apart from the problem mentioned, the way it’s supposed to work is while the shift key is being held down it plays and when it stops being held down it stops, a very basic sprinting system.

Here’s the code:

-- Client -- 
 RunService.RenderStepped:Connect(function()
	
	if UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
		
		Running = true
		Run:FireServer(Running)
	else
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
		local pitch, yaw, roll = camera.CFrame:ToEulerAnglesYXZ()
		char:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(char.HumanoidRootPart.CFrame.p) * CFrame.Angles(0, yaw, 0)
		
		Running = false
		Run:FireServer(Running)
	end
end) 


-- Server -- 
local function EnableSprint(player,Running)
	if not player then return end
	
	local char = player.Character or player.CharacterAdded:Wait()
	local hum = char:FindFirstChild("Humanoid")
	
	if not hum or not player or not char then return end
	
	local IsRunningVal = player:FindFirstChild("IsSprinting")
	local BlockingVal = player:FindFirstChild("Blocking")
	local RunningAnim = player:FindFirstChild("Backpack"):FindFirstChild("Combat"):FindFirstChild("Animations"):WaitForChild("Movement"):WaitForChild("Run")
	local WalkAnim = player:FindFirstChild("Backpack"):FindFirstChild("Combat"):FindFirstChild("Animations"):WaitForChild("Movement"):WaitForChild("Walk")
	local PlayRunAnim = hum:LoadAnimation(RunningAnim)
	local PlayWalkAnim = hum:LoadAnimation(WalkAnim)
	
	if Running == true then
		if IsRunningVal.Value == false and BlockingVal.Value == false then
			IsRunningVal.Value = true
			
			PlayRunAnim:Play()
			hum.WalkSpeed = 22
			print("sprint")			
		else
			return end
		end
		
	
	if Running == false then
		if IsRunningVal.Value == true then
			IsRunningVal.Value = false
			
			PlayRunAnim:Stop(0)
			hum.WalkSpeed = 13
			print("walk")
		else
			return end
		end
	end 

Here’s a video of the issue:

https://gyazo.com/596a325a47ecee31f71a0cfbbafb53e3

You can use Humanoid.MoveDirection to set Running to false and stop the animation and adjust the walkspeed of the character. You would want to run this on the server and fire the remote

if Humanoid.MoveDirection == Vector3.new(0,0,0) then
    Running = false
    PlayRunAnim:Stop()
    hum.WalkSpeed = 13
end

Edit: It looks like the character stopped moving really briefly in the video. If that’s not the case, this won’t work.

That was intentional, I appreciate the response though

where is the EnableSprint() function called?

Run.OnServerEvent:Connect(EnableSprint)

And is there a reason that the server needs to know if the player is sprinting?

Sorry for the late response, I was planning on adding some features to go along with sprinting that I might not want the client to be in control so I figured I would just have the client detect the input and let the server handle what I want to happen

1 Like

try
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 = 25
local Anim = Instance.new(‘Animation’)
Anim.AnimationId = --id here
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)

Wouldn’t that be the same thing? The only difference I see is that you created the animation within the script while mine is preexisting in a folder.

1 Like

I noticed that you put some debuggers for springting vs. walking. Do they print when you hold/release shift?