Advertisement
HowToRoblox

WallrunScript

Jan 8th, 2022
10,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. local c = script.Parent
  2.  
  3. local holdingKey = false
  4.  
  5. local uis = game:GetService("UserInputService")
  6.  
  7. local leftAnim = c.Humanoid:LoadAnimation(script:WaitForChild("WallrunLeft"))
  8. local rightAnim = c.Humanoid:LoadAnimation(script:WaitForChild("WallrunRight"))
  9.  
  10.  
  11. uis.InputBegan:Connect(function(inp, p)
  12.  
  13.     if not p and inp.KeyCode == Enum.KeyCode.F then
  14.  
  15.         holdingKey = true
  16.     end
  17. end)
  18.  
  19. uis.InputEnded:Connect(function(inp)
  20.  
  21.     if inp.KeyCode == Enum.KeyCode.F then
  22.  
  23.         holdingKey = false
  24.     end
  25. end)
  26.    
  27.  
  28. game:GetService("RunService").Heartbeat:Connect(function()
  29.    
  30.     local raycastParams = RaycastParams.new()
  31.     raycastParams.FilterType = Enum.RaycastFilterType.Blacklist; raycastParams.FilterDescendantsInstances = {c}; raycastParams.IgnoreWater = true
  32.    
  33.     local rayL = workspace:Raycast(c.HumanoidRootPart.CFrame.Position, -c.HumanoidRootPart.CFrame.RightVector * 3, raycastParams)
  34.     local rayR = workspace:Raycast(c.HumanoidRootPart.CFrame.Position, c.HumanoidRootPart.CFrame.RightVector * 3, raycastParams)
  35.    
  36.     local ray = rayL or rayR
  37.    
  38.     if ray and holdingKey then
  39.        
  40.         if ray == rayL then
  41.             if not leftAnim.IsPlaying then leftAnim:Play() end
  42.             rightAnim:Stop()
  43.            
  44.         else
  45.             if not rightAnim.IsPlaying then rightAnim:Play() end
  46.             leftAnim:Stop()
  47.         end
  48.        
  49.         local part = ray.Instance
  50.        
  51.         local weld = c.HumanoidRootPart:FindFirstChild("WallrunWeld") or Instance.new("WeldConstraint")
  52.         weld.Name = "WallrunWeld"
  53.            
  54.         weld.Part0 = c.HumanoidRootPart
  55.         weld.Part1 = part
  56.  
  57.         local bp = c.HumanoidRootPart:FindFirstChild("WallrunBodyPosition") or Instance.new("BodyPosition", c.HumanoidRootPart)
  58.         bp.Name = "WallrunBodyPosition"
  59.         bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  60.         bp.Position = c.HumanoidRootPart.Position + c.HumanoidRootPart.CFrame.LookVector * 10
  61.            
  62.     else
  63.            
  64.         for i, child in pairs(c.HumanoidRootPart:GetChildren()) do
  65.  
  66.             if child.Name == "WallrunWeld" or child.Name == "WallrunBodyPosition" then
  67.  
  68.                 child:Destroy()
  69.             end
  70.         end
  71.        
  72.         leftAnim:Stop()
  73.         rightAnim:Stop()
  74.     end
  75. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement