Advertisement
RobloxLuaDeveloper

MM2 SILENT AIM KEYBIND

Mar 30th, 2024 (edited)
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.87 KB | None | 0 0
  1. local Keybind = Enum.KeyCode.E
  2.  
  3. local Players = game:GetService("Players")
  4. local LocalPlayer = Players.LocalPlayer
  5. local Workspace = game:GetService("Workspace")
  6. local StarterGui = game:GetService("StarterGui")
  7. local RunService = game:GetService("RunService")
  8. local UIS = game:GetService("UserInputService")
  9.  
  10. local PartHolder = Instance.new("Folder",Workspace)
  11. PartHolder.Name = tostring(math.random(100,100000))
  12.  
  13. function CreatePart()
  14. local Part = Instance.new("Part",PartHolder)
  15. Part.Name = tostring(math.random(100,100000))
  16. Part.Anchored = true
  17. Part.CanCollide = false
  18. Part.CastShadow = false
  19. Part.Massless = true
  20. Part.Position = Vector3.zero
  21. return Part
  22. end
  23.  
  24. local PredictionBox = CreatePart()
  25. PredictionBox.Size = Vector3.new(.5,.5,.5)
  26. PredictionBox.Shape = Enum.PartType.Ball
  27. local Highlight = Instance.new("Highlight",PredictionBox)
  28. Highlight.Adornee = PredictionBox
  29. Highlight.FillTransparency = 0
  30. Highlight.FillColor = Color3.new(1,0,0)
  31. Highlight.OutlineTransparency = 0.5
  32. Highlight.Enabled = true
  33.  
  34. local RayPart = CreatePart()
  35. RayPart.Size = Vector3.new(.1, .1, .1)
  36. RayPart.Transparency = 1
  37.  
  38. local CurrentWeapon
  39.  
  40. function Notification(Title,Message,Time)
  41. StarterGui:SetCore("SendNotification", {
  42. Title = Title,
  43. Text = Message or "",
  44. Duration = Time or 5
  45. })
  46. end
  47.  
  48. local Success, Error = pcall(function()
  49. function isMultiPlayer()
  50. if #Players:GetPlayers() > 1 then
  51. return true
  52. end
  53. return false
  54. end
  55.  
  56. function isHoldingWeapon(GetObject)
  57. local LocalCharacter = LocalPlayer.Character
  58. if LocalCharacter then
  59. for _,Child in pairs(LocalCharacter:GetChildren()) do
  60. if Child:IsA("Tool") then
  61. local Path = Child:FindFirstChild("GunServer") or Child:FindFirstChild("KnifeServer")
  62. if Path then
  63. local Remote = Path:FindFirstChild("ShootStart") or Path:FindFirstChild("FlingKnife")
  64. if Remote then
  65. if GetObject then
  66. return true, Remote
  67. else
  68. return true
  69. end
  70. end
  71. end
  72. end
  73. end
  74. end
  75. return false
  76. end
  77.  
  78. function isBehindWall(Character)
  79. local LocalCharacter = LocalPlayer.Character
  80. if Character and LocalCharacter then
  81. local LocalRoot = LocalCharacter:FindFirstChild("HumanoidRootPart")
  82. local OtherRoot = Character:FindFirstChild("HumanoidRootPart")
  83. if LocalRoot and OtherRoot then
  84. local Ignored = {LocalCharacter, PredictionBox, RayPart}
  85. local Ray = Ray.new(LocalRoot.Position,(OtherRoot.Position - LocalRoot.Position).unit * 9e9)
  86. local Hit = Workspace:FindPartOnRayWithIgnoreList(Ray,Ignored,false,true)
  87. return Hit and not Hit:IsDescendantOf(Character)
  88. end
  89. end
  90. end
  91.  
  92. function isPositionBehindWall(Position, OtherIgnoredInstance)
  93. if Position then
  94. local LocalCharacter = LocalPlayer.Character
  95. if LocalCharacter then
  96. local LocalRoot = LocalCharacter:FindFirstChild("HumanoidRootPart")
  97. if LocalRoot then
  98. RayPart.Position = Position
  99. local Ignored = {LocalCharacter, OtherIgnoredInstance, PredictionBox}
  100. local Ray = Ray.new(LocalRoot.Position,(RayPart.Position - LocalRoot.Position).unit * 9e9)
  101. local Hit = Workspace:FindPartOnRayWithIgnoreList(Ray,Ignored,false,true)
  102. return Hit and Hit ~= RayPart
  103. end
  104. end
  105. end
  106. end
  107.  
  108. function GetClosestTarget()
  109. local ClosestTarget
  110. local ClosestRoot
  111. local ClosestDistance = math.huge
  112. if isMultiPlayer() then
  113. for _,Player in pairs(Players:GetPlayers()) do
  114. if Player ~= LocalPlayer and Player.Team ~= LocalPlayer.Team then
  115. local LocalCharacter = LocalPlayer.Character
  116. local OtherCharacter = Player.Character
  117. if LocalCharacter and OtherCharacter then
  118. local LocalRoot = LocalCharacter:FindFirstChild("HumanoidRootPart")
  119. local OtherRoot = OtherCharacter:FindFirstChild("HumanoidRootPart")
  120. local OtherHumanoid = OtherCharacter:FindFirstChildOfClass("Humanoid")
  121. if LocalRoot and OtherRoot and OtherHumanoid and OtherHumanoid.Health > 0 and not isBehindWall(OtherCharacter) then
  122. local Distance = (LocalRoot.Position - OtherRoot.Position).Magnitude
  123. if Distance < ClosestDistance then
  124. ClosestDistance = Distance
  125. ClosestTarget = Player
  126. ClosestRoot = OtherRoot
  127. end
  128. end
  129. end
  130. end
  131. end
  132. else
  133. local Rigs = Workspace:FindFirstChild("Rigs")
  134. if Rigs and Rigs:IsA("Folder") then
  135. for _,NpcCharacter in pairs(Rigs:GetChildren()) do
  136. local LocalCharacter = LocalPlayer.Character
  137. if NpcCharacter:IsA("Model") and LocalCharacter then
  138. local LocalRoot = LocalCharacter:FindFirstChild("HumanoidRootPart")
  139. local NpcRoot = NpcCharacter:FindFirstChild("HumanoidRootPart")
  140. local NpcHumanoid = NpcCharacter:FindFirstChildOfClass("Humanoid")
  141. if LocalRoot and NpcRoot and NpcHumanoid and NpcHumanoid.Health > 0 and not isBehindWall(NpcCharacter) then
  142. local Distance = (LocalRoot.Position - NpcRoot.Position).Magnitude
  143. if Distance < ClosestDistance then
  144. ClosestDistance = Distance
  145. ClosestTarget = NpcCharacter
  146. ClosestRoot = NpcRoot
  147. end
  148. end
  149. end
  150. end
  151. end
  152. end
  153. if ClosestTarget and ClosestRoot then
  154. return ClosestTarget, ClosestRoot
  155. end
  156. return nil
  157. end
  158.  
  159. function PredictPosition(Root, PredictType)
  160. if Root and Root:IsA("BasePart") and PredictType then
  161. -- local ClosestActualPing = math.floor(LocalPlayer:GetNetworkPing() * 2000)
  162. local Velocity = Root.Velocity
  163. local NewVelocity
  164. local Result
  165. if string.lower(PredictType) == "gun" then
  166. NewVelocity = (Velocity * Vector3.new(1, 0, 1)) * (math.random(20, 30) / 100) + Vector3.new(0, Velocity.Y * (math.random(60,80) / 1000), 0)
  167. elseif string.lower(PredictType) == "knife" then
  168. local LocalCharacter = LocalPlayer.Character
  169. if LocalCharacter then
  170. local LocalRoot = LocalCharacter:FindFirstChild("HumanoidRootPart")
  171. if LocalRoot then
  172. local Distance = (LocalRoot.Position - Root.Position).Magnitude
  173. NewVelocity = (Velocity * Vector3.new(1, 0, 1)) * (math.random(60, 80) / 100) * Distance / 50 + Vector3.new(0, Velocity.Y * (math.random(40,60) / 1000), 0)
  174. end
  175. end
  176. end
  177. if Root and NewVelocity then
  178. Result = Root.Position + NewVelocity
  179. end
  180. if not isPositionBehindWall(Result, Root.Parent) then
  181. return Result
  182. end
  183. end
  184. return nil
  185. end
  186.  
  187. task.spawn(function()
  188. while RunService.Stepped:Wait() do
  189. if PredictionBox then
  190. local Target, Root = GetClosestTarget()
  191. if Target and Root then
  192. local Position = PredictPosition(Root, CurrentWeapon)
  193. if Position then
  194. PredictionBox.Position = Position
  195. end
  196. end
  197. end
  198. end
  199. end)
  200.  
  201. UIS.InputBegan:Connect(function(Key, Focus)
  202. if Focus then return end
  203. if Key.KeyCode == Keybind then
  204. local boolean, Remote = isHoldingWeapon(true)
  205. if boolean and Remote then
  206. if string.find(string.lower(Remote.Parent.Name), "gun") then
  207. CurrentWeapon = "gun"
  208. local args = {
  209. [1] = 1,
  210. [2] = PredictionBox.Position
  211. }
  212. pcall(function() task.spawn(function()
  213. Remote:FireServer(unpack(args))
  214. end) end)
  215. elseif string.find(string.lower(Remote.Parent.Name), "knife") then
  216. CurrentWeapon = "knife"
  217. local LocalCharacter = LocalPlayer.Character
  218. if LocalCharacter then
  219. local LocalRoot = LocalCharacter:FindFirstChild("HumanoidRootPart")
  220. if LocalRoot then
  221. local args = {
  222. [1] = PredictionBox.CFrame,
  223. [2] = LocalRoot.Position
  224. }
  225. pcall(function() task.spawn(function()
  226. Remote:FireServer(unpack(args))
  227. end) end)
  228. end
  229. end
  230. end
  231. end
  232. end
  233. end)
  234.  
  235. end)
  236.  
  237. if Error then
  238. Notification("Error",Error,math.huge)
  239. end
  240.  
  241. Notification("Script Loaded.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement