I have this run script however if a player is spamming the jump button the jump animation will play the first jump then just play running animation of the rest of the spam jumping.
-- Services
local userInputService = game:GetService("UserInputService")
local players = game:GetService("Players")
-- Variables
local player = players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://15720702879"
local track = animator:LoadAnimation(animation)
track.Priority = Enum.AnimationPriority.Movement
local RUN_KEYCODE = Enum.KeyCode.LeftShift
local RUN_SPEED = 40
local WALK_SPEED = 16
-- Togglables
local isSprinting = false -- if player has sprinting toggled
local isMoving = false -- if player is moving
local isInAir = false -- if player is in the air (because of jumping)
local function updateAnimation() -- Updates it based on if the player is moving or if they have sprinting on/off
if isSprinting and isMoving then
hum.WalkSpeed = RUN_SPEED
if not track.IsPlaying then -- makes sure it isnt already playing
track:Play()
end
else
hum.WalkSpeed = WALK_SPEED
track:Stop()
end
end
local function inputBegan(input, processed)
if processed then return end
if input.KeyCode == RUN_KEYCODE then
isSprinting = not isSprinting -- toggles on and off
updateAnimation()
end
end
local function moveDirectionChanged()
isMoving = hum.MoveDirection.Magnitude > 0 -- sets var to true/false depending if they are moving or not
if not isInAir then
updateAnimation()
end
end
userInputService.InputBegan:Connect(inputBegan) -- player presses key (we want them to press shift)
hum:GetPropertyChangedSignal("MoveDirection"):Connect(moveDirectionChanged) -- player moves
-- Additional: Stop sprinting if jumping | Redone
userInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Space then
track:Stop()
isInAir = true
task.wait(.8)
isInAir = false
end
end)