Hi there, thanks for checking.
Introduction
I'm trying to make a crouch feature in my game by changing the player's default Walk, Run, and Idle animation into a custom animation that I have made.
Problem
I managed to change the default animation, but the change is not visible if the player doesn't stop the currently playing animation. For example, if a player was to press the crouch button while running, the player would still be running with the normal animation until they release 'W' (or fall or anything as long as they stop the current animation), and only then if they press 'W' again would they use the crouch walking animation. Here is the script that I'm using.
local UIS = game:GetService("UserInputService") local character = script.Parent local humanoid = character:WaitForChild("Humanoid") local hrp = character:WaitForChild("HumanoidRootPart") local isCrouching = false local defaultWalkSpeed = 16 local defaultJumpPower = 13 local deb = false local StandToCrouchNoLegs = humanoid:LoadAnimation(script:WaitForChild("StandToCrouchNoLegs")) local StandToCrouch = humanoid:LoadAnimation(script:WaitForChild("StandToCrouch")) local CrouchWalkAnim = humanoid:LoadAnimation(script:WaitForChild("CrouchWalkAnim")) local animateScript = character:WaitForChild("Animate") local defaultWalkAnim = animateScript.walk.WalkAnim.AnimationId local defaultRunAnim = animateScript.run.RunAnim.AnimationId local defaultIdleAnim1 = animateScript.idle.Animation1.AnimationId local defaultIdleAnim2 = animateScript.idle.Animation2.AnimationId local function crouch() isCrouching = true StandToCrouchNoLegs:Play() animateScript.walk.WalkAnim.AnimationId = "rbxassetid://8125946204" animateScript.run.RunAnim.AnimationId = "rbxassetid://8125946204" animateScript.idle.Animation1.AnimationId = "rbxassetid://8141361463" animateScript.idle.Animation2.AnimationId = "rbxassetid://8141361463" while humanoid.WalkSpeed > 6 do humanoid.WalkSpeed = humanoid.WalkSpeed - 1 wait(.1) end humanoid.JumpPower = 0 end local function stand() isCrouching = false animateScript.walk.WalkAnim.AnimationId = defaultWalkAnim animateScript.run.RunAnim.AnimationId = defaultRunAnim animateScript.idle.Animation1.AnimationId = defaultIdleAnim1 animateScript.idle.Animation2.AnimationId = defaultIdleAnim2 while humanoid.WalkSpeed < defaultWalkSpeed do humanoid.WalkSpeed = humanoid.WalkSpeed + 1 wait(.1) end humanoid.JumpPower = defaultJumpPower end UIS.InputBegan:Connect(function(input, isTyping) if input.KeyCode == Enum.KeyCode.C and isTyping == false then if deb == false then if isCrouching == false then deb = true crouch() wait(.2) deb = false else deb = true stand() wait(.2) deb = false end end end end)
I couldn't come up with anything to solve this problem. I imagine it would require me to Reload animation (if that exist). Anyway, thank you for reading, a help would be greatly appreciated.