Advertisement
HowToRoblox

ViewmodelHandler

Oct 3rd, 2021
2,142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. local cam = workspace.CurrentCamera
  2.  
  3. game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson
  4.  
  5.  
  6. local arms = game.ReplicatedStorage.ViewmodelArms:Clone()
  7. arms.Parent = cam
  8.  
  9. local lshoulder = arms.LeftUpperArm.LeftShoulder
  10. local rshoulder = arms.RightUpperArm.RightShoulder
  11.  
  12.  
  13. local gun = game.ReplicatedStorage.Gun:Clone()
  14. gun.Parent = arms
  15.  
  16. local m6d = Instance.new("Motor6D")
  17. m6d.C0 = CFrame.new(1, -0.3, -2.3)
  18. m6d.Part0 = arms.Head
  19. m6d.Part1 = gun.PrimaryPart
  20. m6d.Parent = arms.Head
  21.  
  22.  
  23. local ads = false
  24.  
  25. game.Players.LocalPlayer:GetMouse().Button2Down:Connect(function() 
  26.     ads = true
  27. end)
  28.  
  29. game.Players.LocalPlayer:GetMouse().Button2Up:Connect(function()   
  30.     ads = false
  31. end)
  32.  
  33.  
  34. game:GetService("RunService").RenderStepped:Connect(function()
  35.    
  36.     arms.Head.CFrame = cam.CFrame
  37.    
  38.     local aimC1 = m6d.C0 - Vector3.new(0.177, 0.34, -1)
  39.    
  40.     local c1 = ads and aimC1 or CFrame.new()
  41.     m6d.C1 = m6d.C1:Lerp(c1, 0.2)
  42.    
  43.    
  44.     local cf = gun.Left.CFrame * CFrame.Angles(math.rad(90), 0, math.rad(20)) * CFrame.new(0, 1.3, 0)
  45.     lshoulder.C1 = cf:Inverse() * lshoulder.Part0.CFrame * lshoulder.C0
  46.    
  47.     local cf = gun.Right.CFrame * CFrame.Angles(math.rad(90), 0, math.rad(-10)) * CFrame.new(0, 1.3, 0)
  48.     rshoulder.C1 = cf:Inverse() * rshoulder.Part0.CFrame * rshoulder.C0
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement