I updated my animations from R6 to R15 because I think it would fit the game better, however when spam jumping it will cause almost no animations playing.
I don’t understand why some animations still play after it and I think it can also happen when not forcing it by spam jumping.
Some animations that are getting loaded are not for R6 because I am still in the process on changing them, none of these should be played in the video.
Movement System
local renderConnection = nil
local shiftLockEnabled = false
local animationDelay = 0.3
local jumpPower = 50
local walkSpeed = 6
local sprintSpeed = 20
local canSprint = true
local isSprinting = false
local isInAir = false
local activeKeys = {
W = false,
A = false,
S = false,
D = false
}
-- Animations
local animationsRepli = game:GetService("ReplicatedStorage"):WaitForChild("PlayerStuff"):WaitForChild("Animations")
local forwardWalkAnim = hum:LoadAnimation(animationsRepli.ForwardWalkAnim)
local backWalkAnim = hum:LoadAnimation(animationsRepli.BackWalkAnim)
local leftWalkAnim = hum:LoadAnimation(animationsRepli.LeftWalkAnim)
local rightWalkAnim = hum:LoadAnimation(animationsRepli.RightWalkAnim)
local forwardRollAnim = hum:LoadAnimation(animationsRepli.ForwardRollAnim)
local backRollAnim = hum:LoadAnimation(animationsRepli.BackRollAnim)
local leftRollAnim = hum:LoadAnimation(animationsRepli.LeftRollAnim)
local rightRollAnim = hum:LoadAnimation(animationsRepli.RightRollAnim)
local sprintAnim = hum:LoadAnimation(animationsRepli.SprintAnim)
local jumpAnim = hum:LoadAnimation(animationsRepli.JumpAnim)
local fallAnim = hum:LoadAnimation(animationsRepli.FallAnim)
local landAnim = hum:LoadAnimation(animationsRepli.LandAnim)
local animations = {
forwardWalkAnim, backWalkAnim, leftWalkAnim, rightWalkAnim,
sprintAnim,
jumpAnim, fallAnim, landAnim,
forwardRollAnim, backRollAnim, leftRollAnim, rightRollAnim
}
-- Walk Animations
local timeLimit = 0.3
local lastTimePressed = 0
local sprintRenderConnection
local function cameraBobbing(bool)
if sprintRenderConnection then
sprintRenderConnection:Disconnect()
end
if not bool then return end
if bool then
sprintRenderConnection = RS.RenderStepped:Connect(function()
local CT = tick()
if hum.MoveDirection.Magnitude > 0 then
local BobbleX = math.cos(CT*10)*0.35
local BobbleY = math.abs(math.sin(CT*10))*0.35
local Bobble
if shiftLockEnabled then
Bobble = Vector3.new(BobbleX+2, BobbleY+1, 0.35)
else
Bobble = Vector3.new(BobbleX, BobbleY, 0.35)
end
hum.CameraOffset = hum.CameraOffset:Lerp(Bobble, 0.35)
else
if shiftLockEnabled then
hum.CameraOffset = Vector3.new(2, (hum.CameraOffset.Y+1), hum.CameraOffset.Z) * Vector3.new(1, 0.75, 0.75)
else
hum.CameraOffset = Vector3.new(0, hum.CameraOffset.Y, hum.CameraOffset.Z) * Vector3.new(1, 0.75, 0.75)
end
end
end)
end
end
local function stopAllAnimations(besides, noAnimationDelay)
local animationsToStop = table.clone(animations)
local thisAnimationDelay = animationDelay
if noAnimationDelay then
thisAnimationDelay = 0
end
if besides then
for indexAnim, animation in animationsToStop do
for indexBes, beside in besides do
if beside == animation then
table.remove(animationsToStop, indexAnim)
end
end
end
end
for indexAnim, animation in animationsToStop do
if animation.IsPlaying then
animation:Stop(thisAnimationDelay)
end
end
if not besides then return end
for indexBes, beside in besides do
if not beside.IsPlaying then
beside:Play(thisAnimationDelay)
end
end
end
local function updateAnimations()
if isInAir or landAnim.IsPlaying then return end
if fallAnim.IsPlaying then fallAnim:Stop() end
if isSprinting and not activeKeys.S and activeKeys.W and canSprint then
if activeKeys.A and not activeKeys.D and shiftLockEnabled then
stopAllAnimations({sprintAnim, leftWalkAnim}) return
elseif activeKeys.D and not activeKeys.A and shiftLockEnabled then
stopAllAnimations({sprintAnim, rightWalkAnim}) return
end
stopAllAnimations({sprintAnim}) return
elseif isSprinting and not shiftLockEnabled and canSprint then
if activeKeys.W and activeKeys.S then
elseif activeKeys.A and activeKeys.D then
else
stopAllAnimations({sprintAnim}) return
end
elseif not isSprinting or activeKeys.S or not activeKeys.W then
sprintAnim:Stop()
end
if activeKeys.W and not isSprinting and not activeKeys.S then
if shiftLockEnabled and activeKeys.A and not activeKeys.D then
stopAllAnimations({forwardWalkAnim, leftWalkAnim}) return
elseif shiftLockEnabled and activeKeys.D and not activeKeys.A then
stopAllAnimations({forwardWalkAnim, rightWalkAnim}) return
end
stopAllAnimations({forwardWalkAnim}) return
end
if activeKeys.S and not isSprinting and not activeKeys.W then
if shiftLockEnabled and activeKeys.A and not activeKeys.D then
stopAllAnimations({backWalkAnim, leftWalkAnim}) return
elseif shiftLockEnabled and activeKeys.D and not activeKeys.A then
stopAllAnimations({backWalkAnim, rightWalkAnim}) return
elseif shiftLockEnabled then
stopAllAnimations({backWalkAnim}) return
end
stopAllAnimations({forwardWalkAnim}) return
end
if activeKeys.A and not activeKeys.D then
if shiftLockEnabled then
stopAllAnimations({leftWalkAnim}) return
else
stopAllAnimations({forwardWalkAnim}) return
end
end
if activeKeys.D and not activeKeys.A then
if shiftLockEnabled then
stopAllAnimations({rightWalkAnim}) return
else
stopAllAnimations({forwardWalkAnim}) return
end
end
stopAllAnimations()
end
local function beginSprinting()
cameraBobbing(true)
isSprinting = true
sprintAnim:Play(animationDelay)
hum.WalkSpeed = sprintSpeed
humanoidRootPart.Running.PlaybackSpeed = 2
updateAnimations()
end
local function stopSprinting()
cameraBobbing(false)
isSprinting = false
sprintAnim:Stop(animationDelay)
hum.WalkSpeed = walkSpeed
humanoidRootPart.Running.PlaybackSpeed = 0.9
updateAnimations()
end
local function resumeSprinting()
if isSprinting then
beginSprinting()
else
stopSprinting()
end
end
local function landed()
hum.JumpPower = 0
hum.WalkSpeed = 2
stopAllAnimations({landAnim}, true)
cameraBobbing(false)
end
landAnim.Ended:Connect(function()
hum.JumpPower = 50
resumeSprinting()
updateAnimations()
end)
local startAirTime
local endAirTime
local jumped = false
hum.StateChanged:Connect(function(newState, oldState)
if newState == Enum.HumanoidStateType.Jumping then
isInAir = true
jumped = true
startAirTime = tick()
stopAllAnimations({jumpAnim}, false)
elseif newState == Enum.HumanoidStateType.Landed then
fallAnim:Stop()
endAirTime = tick()
isInAir = false
print(endAirTime - startAirTime)
if (endAirTime - startAirTime) >= 0.7 then
-- you can implement falldamage here
landed()
--print("longfall")
else
--print("shortfall")
hum.JumpPower = 0
while fallAnim.IsPlaying do
task.wait()
end
hum.JumpPower = jumpPower
updateAnimations()
end
jumped = false
end
end)
game:GetService("RunService").Stepped:Connect(function()
local RayOrigin = char.HumanoidRootPart.Position
local RayDirection = Vector3.new(0,-3.2,0)
local RayParams = RaycastParams.new()
RayParams.FilterType = Enum.RaycastFilterType.Exclude
RayParams.FilterDescendantsInstances = {char}
local RayCast = workspace:Raycast(RayOrigin, RayDirection, RayParams)
if not RayCast and (hum:GetState() == Enum.HumanoidStateType.Jumping or hum:GetState() == Enum.HumanoidStateType.Freefall) then
if not isInAir then
isInAir = true
startAirTime = tick()
end
if (tick() - startAirTime) > 0.2 then
print(tick() - startAirTime)
stopAllAnimations({fallAnim}, false)
end
else
isInAir = false
updateAnimations()
end
end)
UIS.InputBegan:Connect(function(input, gps)
if gps then return end
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockEnabled = not shiftLockEnabled
tweenOffset(shiftLockEnabled)
updateAnimations()
if shiftLockEnabled then
if not activeKeys.W and isSprinting then
stopSprinting()
end
end
end
-- Double Tap W for Sprinting
if input.KeyCode == Enum.KeyCode.W then
local currentTime = tick()
if currentTime - lastTimePressed <= timeLimit and canSprint and not isSprinting then
beginSprinting()
end
lastTimePressed = currentTime
end
if input.KeyCode == Enum.KeyCode.W and isSprinting then
activeKeys.W = true
elseif input.KeyCode == Enum.KeyCode.W then
activeKeys.W = true
elseif input.KeyCode == Enum.KeyCode.A then
activeKeys.A = true
elseif input.KeyCode == Enum.KeyCode.S then
activeKeys.S = true
elseif input.KeyCode == Enum.KeyCode.D then
activeKeys.D = true
end
updateAnimations()
end)
UIS.InputEnded:Connect(function(input, gas)
if gas then return end
if input.KeyCode == Enum.KeyCode.W and shiftLockEnabled then
if isSprinting then
stopSprinting()
end
activeKeys.W = false
elseif input.KeyCode == Enum.KeyCode.W then
activeKeys.W = false
elseif input.KeyCode == Enum.KeyCode.A then
activeKeys.A = false
elseif input.KeyCode == Enum.KeyCode.S then
activeKeys.S = false
elseif input.KeyCode == Enum.KeyCode.D then
activeKeys.D = false
end
if not shiftLockEnabled then
local deactivateSprinting = true
for indexKey, key in activeKeys do
if key == true then
deactivateSprinting = false
end
end
if deactivateSprinting then
stopSprinting()
end
end
updateAnimations()
end)