Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make the animation in my Shift To Crawl script play and stop instantly?

Asked by 1 year ago
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local animate = char:WaitForChild("Animate")
local ui = game:GetService("UserInputService")
local crawlin = false



ui.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftShift and crawlin == false then
        crawlin = true
        hum.WalkSpeed = 10
        hum.JumpPower = 25
        animate.walk.WalkAnim.AnimationId = "rbxassetid://10912465913" --action priority
        animate.idle.Animation1.AnimationId = "rbxassetid://10918439489" --idle priority
        animate.idle.Animation2.AnimationId = "rbxassetid://10918439489" --idle priority
    elseif  input.KeyCode == Enum.KeyCode.LeftShift and crawlin == true then
        crawlin = false
        hum.WalkSpeed = 16
        hum.JumpPower = 50
        animate.walk.WalkAnim.AnimationId = "rbxassetid://180426354" --action priority
        animate.idle.Animation1.AnimationId = "rbxassetid://180435571" --idle priority
        animate.idle.Animation2.AnimationId = "rbxassetid://180435792" --idle priority
    end
end)

While it does work, there's a slight issue. When "Shift" is pressed, the animation doesn't play instantly until the player moves. In addition, if the player is walking and pressed shift, the animation wouldn't work until they have stopped. Same thing happens when the player is crawling and presses shift. I want my crawl to look like the one in Flee The Facility on Roblox if it helps, any help is appreciated!

0
if you want me to elaborate more on my answer I can Kingu_Criminal 205 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Changing the animate script of the character itself is really bad, simply play an animation over them (higher priority) Use input

local uis = game:GetService("UserInputService)

local function CheckKeyDown()
    --check key down
end

local function CheckKeyUp()
    --check key up
end

uis.InputBegan:Connect(CheckKeyDown)
uis.InputEnded:Connect(CheckKeyUp)

Ad

Answer this question