Well, my problem is that sometimes it works and sometimes the anim: Stop () doesn’t and I really don’t know how to fix it.
Edit: I have noticed that the errors gives us when you are not moving, after moving it will not give the errors.
Line 36
local uis = game:GetService("UserInputService")
local crawlAnimation = script:WaitForChild("Crawl")
local loadedCrawlAnim
local crawlIdle = script:WaitForChild("CrawlIdle")
local loadedIdleAnim
local isCrawling = false
local humanoid = script.Parent:FindFirstChild("Humanoid")
local KeyText = "C"
uis.InputBegan:Connect(function(key, gameProcessed)
if key.KeyCode.Name == KeyText then
if isCrawling then
isCrawling = false
if loadedCrawlAnim then loadedCrawlAnim:Stop() end
loadedIdleAnim:Stop()
elseif not isCrawling then
isCrawling = true
loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
loadedIdleAnim:Play()
end
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
if not isCrawling then return end
if humanoid.MoveDirection.Magnitude > 0 then
if not loadedCrawlAnim then loadedCrawlAnim = humanoid:LoadAnimation(crawlAnimation) end
if loadedCrawlAnim.IsPlaying == false then loadedCrawlAnim:Play() end
else
loadedCrawlAnim:Stop()
loadedIdleAnim:Play()
end
end)