Facebook
From Colossal Owl, 1 Year ago, written in Lua.
This paste is a reply to [Roblox Studio] Shift to Sprint with Animation from Truscco - view diff
Embed
Download Paste or View Raw
Hits: 244
  1. local character = script.Parent
  2. local humanoid = character:WaitForChild("Humanoid")
  3.  
  4. local contextActionService = game:GetService("ContextActionService")
  5.  
  6. local running = false
  7.  
  8. local runAnim = Instance.new("Animation")
  9. runAnim.AnimationId = "rbxassetid://5832447211"
  10.  
  11. local loadedRun = humanoid:LoadAnimation(runAnim)
  12.  
  13. --//Functions
  14.  
  15. local function handler(actionName, inputState, inputObject)
  16.   if actionName == "Run" then
  17.     if inputState == Enum.UserInputState.Begin then
  18.       humanoid.WalkSpeed = 26
  19.       loadedRun:Play()
  20.       running = true
  21.     end
  22.     if inputState == Enum.UserInputState.End then
  23.       if loadedRun.IsPlaying then
  24.         loadedRun:Stop()
  25.       end
  26.       humanoid.WalkSpeed = 16
  27.       running = false
  28.     end
  29.   end
  30. end
  31.  
  32. contextActionService:BindAction("Run", handler, false, Enum.KeyCode.LeftShift)
  33.  
  34. while wait() do
  35.   if humanoid.MoveDirection.Magnitude <= 0 and running then
  36.     if loadedRun.IsPlaying then
  37.       loadedRun:Stop()
  38.     end
  39.     humanoid.WalkSpeed = 16
  40.     running = false
  41.   end
  42. end
  43.  
  44. humanoid.Jumping:Connect(function(active)
  45.     if active == false and running == true then
  46.       loadedRun:Play()
  47.     end
  48. end)