Im making a jojo-inspired game and Im working on making the stand lean whenever the player is moving or running. I want to make it so that the idle animation doesnt start playing if the player quickly switches between moving left and right and ends up pressing both a and d for a split second. This works, although when you hold down both keys I made is so that the stands idle animation plays after a a second. Problem is that when you stop holding both keys the animation that you didnt hold both keys down during (ex: after holding down both a and d for a few seconds while walking, after you release the stand’s running animation brakes) Why is this happening?
local RunService = game:GetService("RunService")
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character.Humanoid
local uis = game:GetService("UserInputService")
local Stand = script.Parent
local SprintAnim = Stand.AnimationController:LoadAnimation(script:WaitForChild("Run"))
SprintAnim:Play()
local LeanAnim = Stand.AnimationController:LoadAnimation(script:WaitForChild("Lean"))
LeanAnim:Play()
function TwoDown()
if uis:IsKeyDown(Enum.KeyCode.A) and uis:IsKeyDown(Enum.KeyCode.D) or uis:IsKeyDown(Enum.KeyCode.W) and uis:IsKeyDown(Enum.KeyCode.S) then
return true
else
return false
end
end
RunService.Heartbeat:Connect(function()
if Humanoid.MoveDirection == Vector3.new(0, 0, 0) then
if TwoDown() then
wait(.3)
if TwoDown() then
LeanAnim:AdjustWeight(0)
SprintAnim:AdjustWeight(0)
end
else
LeanAnim:AdjustWeight(0)
SprintAnim:AdjustWeight(0)
end
elseif Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) and uis:IsKeyDown(Enum.KeyCode.LeftShift) then
SprintAnim:AdjustWeight(1.001)
LeanAnim:AdjustWeight(0)
elseif Humanoid.MoveDirection ~= Vector3.new(0, 0, 0) then
LeanAnim:AdjustWeight(1.001)
SprintAnim:AdjustWeight(0)
end
end)
walk anim braking
running anim braking: