Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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!

1 comment

0

if you want me to elaborate more on my answer I can

1 answer

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.