thomas13215

nocol guns first person

Apr 3rd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.76 KB | None | 0 0
  1. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  2. -- StarterGui --
  3. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  4. -- Place this into StarterGui or StarterPack --
  5. -- CREDIT --
  6. -- WhoBloxxedWho; for the initial script --
  7. -- DoogleFox; some stuff ripped from his panner script --
  8. -- DuruTeru; shoving it all into this script and then some :) --
  9. -- UPDATE: turned it into r15, made it so you can swim right in water --
  10. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
  11.  
  12.  
  13. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  14.  
  15.  
  16. repeat wait() until game:GetService("Players").LocalPlayer.Character ~= nil
  17. local runService = game:GetService("RunService")
  18. local input = game:GetService("UserInputService")
  19. local players = game:GetService("Players")
  20.  
  21. CanToggleMouse = {allowed = true; activationkey = Enum.KeyCode.F;} -- lets you move your mouse around in firstperson
  22. CanViewBody = true -- whether you see your body
  23. Sensitivity = 1 -- anything higher would make looking up and down harder; recommend anything between 0~1
  24. Smoothness = 0.05 -- recommend anything between 0~1
  25. FieldOfView = 90 -- fov
  26.  
  27. local cam = game.Workspace.CurrentCamera
  28. local player = players.LocalPlayer
  29. local m = player:GetMouse()
  30. m.Icon = "http://www.roblox.com/asset/?id=569021388" -- replaces mouse icon
  31. local character = player.Character or player.CharacterAdded:wait()
  32. local humanoidpart = character.HumanoidRootPart
  33.  
  34. local head = character:WaitForChild("Head")
  35. local CamPos,TargetCamPos = cam.CoordinateFrame.p,cam.CoordinateFrame.p
  36. local AngleX,TargetAngleX = 0,0
  37. local AngleY,TargetAngleY = 0,0
  38.  
  39. local running = true
  40. local freemouse = false
  41.  
  42. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  43.  
  44. function updatechar()
  45.  
  46. for _, v in pairs(character:GetChildren())do
  47. if CanViewBody then
  48. if v.Name == 'Head' then
  49. v.LocalTransparencyModifier = 1
  50. v.CanCollide = false
  51. end
  52. else
  53. if v:IsA'Part' or v:IsA'UnionOperation' or v:IsA'MeshPart' then
  54. v.LocalTransparencyModifier = 1
  55. v.CanCollide = false
  56. end
  57. end
  58. if v:IsA'Accessory' then
  59. v:FindFirstChild('Handle').LocalTransparencyModifier = 1
  60. v:FindFirstChild('Handle').CanCollide = false
  61. end
  62. if v:IsA'Hat' then
  63. v:FindFirstChild('Handle').LocalTransparencyModifier = 1
  64. v:FindFirstChild('Handle').CanCollide = false
  65. end
  66.  
  67. end
  68.  
  69. end
  70.  
  71. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  72.  
  73. input.InputChanged:connect(function(inputObject)
  74.  
  75. if inputObject.UserInputType == Enum.UserInputType.MouseMovement then
  76. local delta = Vector2.new(inputObject.Delta.x/Sensitivity,inputObject.Delta.y/Sensitivity) * Smoothness
  77.  
  78. local X = TargetAngleX - delta.y
  79. TargetAngleX = (X >= 80 and 80) or (X <= -80 and -80) or X
  80. TargetAngleY = (TargetAngleY - delta.x) %360
  81. end
  82.  
  83. end)
  84.  
  85. input.InputBegan:connect(function(inputObject)
  86.  
  87. if inputObject.UserInputType == Enum.UserInputType.Keyboard then
  88. if inputObject.KeyCode == CanToggleMouse.activationkey then
  89. if CanToggleMouse.allowed and freemouse == false then
  90. freemouse = true
  91. else
  92. freemouse = false
  93. end
  94. end
  95. end
  96.  
  97. end)
  98.  
  99. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
  100.  
  101. runService.RenderStepped:connect(function()
  102.  
  103. if running then
  104. updatechar()
  105.  
  106. CamPos = CamPos + (TargetCamPos - CamPos) *0.28
  107. AngleX = AngleX + (TargetAngleX - AngleX) *0.35
  108. local dist = TargetAngleY - AngleY
  109. dist = math.abs(dist) > 180 and dist - (dist / math.abs(dist)) * 360 or dist
  110. AngleY = (AngleY + dist *0.35) %360
  111. cam.CameraType = Enum.CameraType.Scriptable
  112.  
  113. cam.CoordinateFrame = CFrame.new(head.Position)
  114. * CFrame.Angles(0,math.rad(AngleY),0)
  115. * CFrame.Angles(math.rad(AngleX),0,0)
  116. * CFrame.new(0,0.5,0) -- offset
  117.  
  118. humanoidpart.CFrame=CFrame.new(humanoidpart.Position)*CFrame.Angles(0,math.rad(AngleY),0)
  119. else game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
  120. end
  121.  
  122. if (cam.Focus.p-cam.CoordinateFrame.p).magnitude < 1 then
  123. running = false
  124. else
  125. running = true
  126. if freemouse == true then
  127. game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.Default
  128. else
  129. game:GetService("UserInputService").MouseBehavior = Enum.MouseBehavior.LockCenter
  130. end
  131. end
  132.  
  133. if not CanToggleMouse.allowed then
  134. freemouse = false
  135. end
  136.  
  137. cam.FieldOfView = FieldOfView
  138.  
  139. end)
  140.  
  141. ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
Add Comment
Please, Sign In to add comment