Advertisement
Guest User

Wall Climbing System Roblox

a guest
Apr 22nd, 2022
5,772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.52 KB | None | 0 0
  1. --Simple setup:
  2. -- 1) Go to starter player, then starter character scripts
  3. -- 2) create a local script inside of it
  4. -- 3) paste the code underneath into it
  5. -- And you're done!
  6.  
  7. local wall = nil
  8.  
  9. local hrp = script.Parent:WaitForChild("HumanoidRootPart")
  10.  
  11. local anim = script.Parent:WaitForChild("Humanoid"):LoadAnimation(script.Parent:WaitForChild("Animate").climb.ClimbAnim)
  12.  
  13. local uis = game:GetService("UserInputService")
  14.  
  15.  
  16.  
  17. game:GetService("RunService").Heartbeat:Connect(function()
  18.  
  19.     local raycastParams = RaycastParams.new()
  20.     raycastParams.FilterDescendantsInstances = {script.Parent}
  21.  
  22.     local raycastResult = workspace:Raycast(script.Parent.LeftFoot.Position, hrp.CFrame.LookVector * 2.5, raycastParams)
  23.  
  24.     wall = raycastResult and raycastResult.Instance or nil
  25.     local w = uis:IsKeyDown(Enum.KeyCode.W)
  26.     local s = uis:IsKeyDown(Enum.KeyCode.S)
  27.     local a = uis:IsKeyDown(Enum.KeyCode.A)
  28.     local d = uis:IsKeyDown(Enum.KeyCode.D)
  29.  
  30.    
  31.     if wall then -- on the wall
  32.         if w then -- go up
  33.             anim:AdjustSpeed(1)
  34.  
  35.             hrp.Velocity = Vector3.new(hrp.Velocity.X, 20, hrp.Velocity.Z)
  36.             workspace.Gravity = 0
  37.  
  38.             if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
  39.             if not anim.IsPlaying then anim:Play() end
  40.         elseif a then
  41.             anim:AdjustSpeed(1)
  42.  
  43.             hrp.Velocity = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
  44.             workspace.Gravity = 0
  45.  
  46.             if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
  47.             if not anim.IsPlaying then anim:Play() end
  48.         elseif s then
  49.             anim:AdjustSpeed(1)
  50.  
  51.             hrp.Velocity = Vector3.new(hrp.Velocity.X, -20, hrp.Velocity.Z)
  52.             workspace.Gravity = 0
  53.  
  54.             if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
  55.             if not anim.IsPlaying then anim:Play() end
  56.         elseif d then
  57.             anim:AdjustSpeed(1)
  58.  
  59.             hrp.Velocity = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
  60.             workspace.Gravity = 0
  61.  
  62.             if script.Parent.Humanoid:GetState() ~= Enum.HumanoidStateType.Climbing then script.Parent.Humanoid:ChangeState(Enum.HumanoidStateType.Climbing) end
  63.             if not anim.IsPlaying then anim:Play() end
  64.            
  65.         elseif not w then -- pausing on the wall
  66.             hrp.Velocity = Vector3.new(hrp.Velocity.X, 0, hrp.Velocity.Z)
  67.             anim:AdjustSpeed(0)
  68.         end
  69.     else -- off the wall
  70.         workspace.Gravity = 196.6
  71.         anim:Stop()
  72.     end
  73. end)
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement