How do i make animations properly play with a sprint script?

im trying to figure out how to make it so that the animation only plays when the start to actually run instead of just standing still

What i have currently:

local UserInputService = game:GetService("UserInputService")

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

local Status = Character:WaitForChild("Status")
local SprintCheck = Character:WaitForChild("SprintCheck")

local Humanoid =  Character:WaitForChild("Humanoid")
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")

local Animator = Humanoid:WaitForChild("Animator")
local RunTrack = Animator:LoadAnimation(script:WaitForChild("RunAnim"))




UserInputService.InputBegan:Connect(function(Input,IsTyping)
	if Input.KeyCode == Enum.KeyCode.LeftControl then
		if SprintCheck.Value == true then
			RunTrack:Stop()
			SprintCheck.Value = false -- Gonna change this later to do it on server side
			Humanoid.WalkSpeed = 16
			print("NotSprinting")
		elseif SprintCheck.Value == false then
			RunTrack:Play()
			SprintCheck.Value = true -- Gonna change this later to do it on server side
			Humanoid.WalkSpeed = 24
			print("Sprinting")
		end
	end
end)

You need it split it up between 'InputBegan" and “InputEnded”.
As it is now, you only have InputBegan

nah that doesnt work either if you keep holding down the key while moving still then the animation will still play

and also changing the roblox run animation from animate wont either cause it requires the player to stop moving before refreshing the animation

besides im making a toggle sprint system

I just changed a tiny bit of your code but this should work:

local UserInputService = game:GetService("UserInputService")

local Player = game.Players.LocalPlayer

local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait()
local Humanoid =  Character:FindFirstChildOfClass("Humanoid")
local Animator = Humanoid:FindFirstChildOfClass("Animator")

local RunTrack = Animator:LoadAnimation(script.RunAnim)
RunTrack.Looped = true

local IsRunning = false

UserInputService.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then return end
	
	if Input.KeyCode == Enum.KeyCode.LeftControl then
		IsRunning = not IsRunning
		
		if IsRunning then
			RunTrack:Play()
			Humanoid.WalkSpeed = 24
		else
			RunTrack:Stop()
			Humanoid:ResetPropertyToDefault("WalkSpeed")
		end
	end
end)

no im trying to make it so that the animation only plays while the player walks/runs

Based on your recent comments you said you wanted it to only be toogleable. Just check the movedirection when the condition runs

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.