im trying to put the animation and the sprint in one script and ive done this and my animation is not playing anymore,
local Players = game:GetService("Players")
local CAS = game:GetService("ContextActionService")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = Character:WaitForChild("Humanoid")
local animation = script:WaitForChild("AnimationRun")
local animationTrack = humanoid:LoadAnimation(animation)
local running = false
local function isMoving()
return humanoid.MoveDirection.Magnitude > 0
end
local function sprint()
if running and isMoving() == true then
animationTrack:Play()
animationTrack:AdjustSpeed(1.35)
else
animationTrack:Stop()
end
end
humanoid.Running:Connect(function(speed)
if speed == 0 then
animationTrack:Stop()
elseif running and not animationTrack.IsPlaying then
animationTrack:Play()
animationTrack:AdjustSpeed(1.35)
end
end)
local function handleSprint(shouldSprint)
if shouldSprint == true then
humanoid.WalkSpeed = 22
else
humanoid.WalkSpeed = 10
end
end
local function handleInput(actionName,inputState,inputObject)
if actionName == "Sprint" then
local shouldSprint = false
if inputState == Enum.UserInputState.Begin then
shouldSprint = true
end
handleSprint(shouldSprint)
sprint()
end
end
local function listenInput()
CAS:BindAction("Sprint",handleInput,true,Enum.KeyCode.LeftShift,Enum.KeyCode.ButtonL1)
CAS:SetTitle("Sprint", "Sprint")
CAS:SetPosition("Sprint", UDim2.new(1, -70, 0, 10))
end
listenInput()