so basically i have this code and i want the change the running animation when i press shift but it wont work.
(this is a local script)
local runningAnimation = Instance.new('Animation')
local jumpingAnimation = Instance.new('Animation')
local keyboardButtonPressed = false
local controllerButtonPressed = false
local defaultSpeed = 10
local sprintSpeed = 24
local FOV = 70
local walkingFOV = {FieldOfView = FOV}
local sprintFOV = {FieldOfView = FOV + 10}
local tweenTime = 1
local keyboardButton = Enum.KeyCode.LeftShift
local controllerButton = Enum.KeyCode.ButtonL2
local tweenEasingStyle = Enum.EasingStyle.Exponential
local tweenEasingDirection = Enum.EasingDirection.Out
runningAnimation.AnimationId = 'rbxassetid://9913645916'
jumpingAnimation.AnimationId = 'rbxassetid://0'
local keepJumpingAnimation = false
local player = script.Parent
local humanoid = player:WaitForChild("Humanoid",5)
local camera = game.workspace.CurrentCamera
local animator = humanoid:WaitForChild("Animator")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local playRunning = humanoid:LoadAnimation(runningAnimation)
local playJumping = humanoid:LoadAnimation(jumpingAnimation)
local Info = TweenInfo.new(tweenTime, tweenEasingStyle, tweenEasingDirection)
local runningT = TweenService:Create(camera, Info, sprintFOV)
local walkingT = TweenService:Create(camera, Info, walkingFOV)
UserInputService.InputBegan:Connect(function(input,gameProcessedEvent)
if input.KeyCode == keyboardButton then
keyboardButtonPressed = true
while keyboardButtonPressed == true do
wait()
humanoid.WalkSpeed = sprintSpeed
end
end
if input.KeyCode == controllerButton then
controllerButtonPressed = true
while controllerButtonPressed == true do
wait()
humanoid.WalkSpeed = sprintSpeed
end
end
end)
UserInputService.InputEnded:Connect(function(input,gameProcessedEvent)
if input.KeyCode == keyboardButton then
keyboardButtonPressed = false
while keyboardButtonPressed == false do
wait()
humanoid.WalkSpeed = defaultSpeed
end
end
if input.KeyCode == controllerButton then
controllerButtonPressed = false
while controllerButtonPressed == false do
wait()
humanoid.WalkSpeed = defaultSpeed
end
end
end)
-- Checks if your speed is over than the defaultSpeed by 1, Which it assumes that you're running, and plays the animation.
humanoid.Running:Connect(function(Speed)
if Speed > defaultSpeed + 1 then
if not playRunning.IsPlaying then
runningT:Play()
playRunning:Play()
end
else
walkingT:Play()
playRunning:Stop()
end
end)
humanoid.Jumping:Connect(function()
if playRunning.IsPlaying then
playRunning:Stop()
if keepJumpingAnimation == true then
playJumping:Play()
end
end
end)

1 comment
Can I give u a suggest. I would recommend you just have a sprint button, because mobile players won't be able to use sprint.