I have a crawl script that fires when typing c, and that doesn’t always use the crawl animation while in the crouch. Here is the script.
crawling = false
local humanoid = script.Parent.Humanoid
crawlAnim = nil
crawlAnimIdle = nil
game:GetService(“UserInputService”).InputBegan:connect(function(input)
if input.KeyCode == Enum.KeyCode.C then
if crawling == true then
crawling = false
crawlAnim:Stop()
crawlAnim:Destroy()
crawlAnimIdle:Stop()
crawlAnimIdle:Destroy()
humanoid.WalkSpeed = humanoid.WalkSpeed*2
humanoid.Parent.Head.Running.PlaybackSpeed = 1.85
else
crawling = true
crawlAnim = humanoid:LoadAnimation(script.CrawlAnim)
crawlAnimIdle = humanoid:LoadAnimation(script.CrawlAnimIdle)
humanoid.WalkSpeed = humanoid.WalkSpeed/2
humanoid.Parent.Head.Running.PlaybackSpeed = 1
end
end
end)
while wait()do
if crawling == true then
crawlAnim:AdjustSpeed(humanoid.WalkSpeed/8)
if humanoid.MoveDirection ~= Vector3.new(0,0,0)then
if crawlAnim.IsPlaying ~= true then
crawlAnim:Play()
end
else
crawlAnim:Stop()
crawlAnimIdle:Play()
end
end
end
If you put your script inside three of these " ``` " (Without the " ") then it will make a code block and it will be a lot easier to read. Also please make sure that the code is indented correctly!
however, the issue where you can crawl while typing is an easy fix!
You can use UserInputService:GetFocusedTextBox() to check if the player is typing in a text box before doing anything involving your crawling system.
As to your other issue, I think you’re referring to it doesn’t always play the idle/move animation when it’s supposed to? If your Humanoid.MoveDirection method isn’t working, you could try using either the Humanoid.Running event or the Humanoid.StateChanged event (however I’ve heard/found StateChanged doesn’t always work correctly, I’ve found .Running to be more reliable). Using this method, play your idle animation when the speed returned by the event is less than a small speed such as 1 (just in case your event happens to not return 0), and play your movement animation when the speed is greater than 1.