Advertisement
HowToRoblox

CrawlHandler

May 6th, 2020
7,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local uis = game:GetService("UserInputService")
  2.  
  3. local crawlAnimation = script:WaitForChild("Crawl")
  4. local loadedCrawlAnim
  5.  
  6. local crawlIdle = script:WaitForChild("CrawlIdle")
  7. local loadedIdleAnim
  8.  
  9. local isCrawling = false
  10.  
  11. local humanoid = script.Parent:FindFirstChild("Humanoid")
  12.  
  13.  
  14. uis.InputBegan:Connect(function(key, gameProcessed)
  15.        
  16.     if key.KeyCode == Enum.KeyCode.C then
  17.                
  18.        
  19.         if isCrawling then
  20.        
  21.             isCrawling = false 
  22.            
  23.             if loadedCrawlAnim then loadedCrawlAnim:Stop() end 
  24.            
  25.             loadedIdleAnim:Stop()          
  26.            
  27.             game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 16, 50)
  28.                
  29.         elseif not isCrawling then
  30.  
  31.             isCrawling = true  
  32.    
  33.             loadedIdleAnim = humanoid:LoadAnimation(crawlIdle)
  34.             loadedIdleAnim:Play()
  35.            
  36.             game.ReplicatedStorage.OnCrouchBegun:FireServer(humanoid, 3, 20)
  37.         end
  38.     end
  39. end)
  40.  
  41.  
  42. game:GetService("RunService").RenderStepped:Connect(function()
  43.        
  44.     if not isCrawling then return end
  45.        
  46.     if humanoid.MoveDirection.Magnitude > 0 then
  47.        
  48.         if not loadedCrawlAnim then loadedCrawlAnim = humanoid:LoadAnimation(crawlAnimation) end
  49.         if loadedCrawlAnim.IsPlaying == false then loadedCrawlAnim:Play() end  
  50.  
  51.     else
  52.         loadedCrawlAnim:Stop()
  53.         loadedIdleAnim:Play()
  54.     end
  55. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement