Advertisement
anphu04

Murder Mystery 2 - FULLY AUTOMATE

Aug 29th, 2023 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.92 KB | None | 0 0
  1. -- 28/2/2023: last exploit(s) before going home tomorrow
  2. COIN_TYPE = {'BeachBall'}
  3.  
  4. myplr = game.Players.LocalPlayer
  5. cam = workspace.CurrentCamera
  6. uis = game:GetService('UserInputService')
  7. pathfinder = game:GetService('PathfindingService')
  8. tweener = game:GetService('TweenService')
  9. vim = game:GetService('VirtualInputManager')
  10. run = game:GetService('RunService')
  11.  
  12. for i,v in pairs(workspace:GetDescendants()) do
  13.     if v.Name == 'CoinContainer' then
  14.         container = v
  15.         break
  16.     end
  17. end
  18. spawn(function()
  19.     while wait(2) do
  20.         if stop then break end
  21.  
  22.         -- prevent 20 minutes idle disconnection
  23.         if not hasgun then
  24.             vim:SendMouseButtonEvent(0,0,0, true, game,1)
  25.             vim:SendMouseButtonEvent(0,0,0, false, game,1)
  26.         end
  27.  
  28.         for i,v in pairs(workspace:GetDescendants()) do
  29.             if v.Name == 'CoinContainer' then
  30.                 container = v
  31.                 break
  32.             end
  33.         end
  34.     end
  35. end)
  36.  
  37. --/////////////////////////////////////////
  38.  
  39. event = nil
  40. stop = false
  41. event = uis.InputBegan:Connect(function(input,gpe)
  42.     if gpe then return end
  43.     if input.KeyCode == Enum.KeyCode.X then
  44.         stop = true
  45.     end
  46. end)
  47. --/////////////////////////////////////////////////////////
  48.  
  49. function createPath(from,to)
  50.     local agentParams = {
  51.         AgentHeight = 2.5,
  52.         AgentRadius = 2,
  53.         AgentCanJump = true
  54.     }
  55.     local path = pathfinder:CreatePath(agentParams)
  56.     path:ComputeAsync(from,to)
  57.     if path.Status == Enum.PathStatus.Success then
  58.         local waypoints = path:GetWaypoints()
  59.         return path,waypoints
  60.     end
  61. end
  62.  
  63. function insight(from,target) -- make sure no players see us or we'll be accused of cheating
  64.     for i,plr in pairs(game.Players:GetChildren()) do
  65.         if plr ~= myplr then
  66.             local params = RaycastParams.new()
  67.             params.FilterType = Enum.RaycastFilterType.Exclude
  68.             params.FilterDescendantsInstances = {myplr.Character}
  69.  
  70.             local result = workspace:Raycast(from, (target.Position-from).Unit*150, params)
  71.             if result and result.Instance then
  72.                 if result.Instance == target or result.Instance:IsDescendantOf(target) then
  73.                     return true
  74.                 end
  75.             end
  76.  
  77.         end
  78.     end
  79. end
  80. --////////////////////////////////////////////
  81.  
  82. clip = true
  83. function Nocl()
  84.     if game.Players.LocalPlayer.Character ~= nil then
  85.         for _,v in pairs(game.Players.LocalPlayer.Character:GetDescendants()) do
  86.             if v:IsA("BasePart") and (v.CanCollide or v.Name == 'HumanoidRootPart' or v.Name == 'UpperTorso' or v.Name == 'LowerTorso') then
  87.                 v.CanCollide = clip == true and true or false
  88.             end
  89.         end
  90.     end
  91.     wait(0.21) -- basic optimization
  92. end
  93. Noclip = game:GetService('RunService').Stepped:Connect(Nocl)
  94.  
  95. --////////////////////////////////////////////////////////
  96.  
  97. killer = nil
  98. spawn(function()
  99.     while not stop do
  100.         wait()
  101.         for i,plr in pairs(game.Players:GetChildren()) do
  102.             if plr ~= myplr and plr.Character and plr.Character:FindFirstChild('Knife') then
  103.                 killer = plr.Character
  104.             end
  105.         end
  106.     end
  107. end)
  108.  
  109. function killerinsight()
  110.     local result = workspace:Raycast(cam.CFrame.p, (killer.HumanoidRootPart.Position - cam.CFrame.p).Unit*150)
  111.     return (result and result.Instance and result.Instance:IsDescendantOf(killer)) and true or false
  112. end
  113.  
  114.  
  115. --////////////////////////////////////////////////////////
  116.  
  117. function isInLobby()
  118.     if root and root.Parent then
  119.         local touches = workspace:GetPartBoundsInBox(
  120.             root.CFrame,
  121.             Vector3.new(2,20,2)
  122.         )
  123.         for i,v in pairs(touches) do
  124.             if v:IsDescendantOf(workspace.Lobby) then
  125.                 return true
  126.             end
  127.         end
  128.         return false
  129.     else -- root not found meaning that we just died and havent yet respawned into the lobby
  130.         return true
  131.     end
  132. end
  133.  
  134. --////////////////////////////////////////////////////////
  135.  
  136.  function distanceToLine(point, lineStart, lineEnd)
  137.     local vector = Vector3.new(
  138.         lineEnd.X - lineStart.X,
  139.         lineEnd.Y - lineStart.Y,
  140.         lineEnd.Z - lineStart.Z
  141.     )
  142.     local pointVector = Vector3.new(
  143.         point.X - lineStart.X,
  144.         point.Y - lineStart.Y,
  145.         point.Z - lineStart.Z
  146.     )
  147.  
  148.     local vectorMagnitude = math.sqrt(vector.X^2 + vector.Y^2 + vector.Z^2)
  149.     local normalizedVector = Vector3.new(vector.X / vectorMagnitude, vector.Y / vectorMagnitude, vector.Z / vectorMagnitude)
  150.  
  151.     local dotProduct = pointVector.X * normalizedVector.X + pointVector.Y * normalizedVector.Y + pointVector.Z * normalizedVector.Z
  152.     local projectedPoint = Vector3.new(
  153.         lineStart.X + dotProduct * normalizedVector.X,
  154.         lineStart.Y + dotProduct * normalizedVector.Y,
  155.         lineStart.Z + dotProduct * normalizedVector.Z
  156.     )
  157.  
  158.     local distance = math.sqrt((projectedPoint.X - point.X)^2 + (projectedPoint.Y - point.Y)^2 + (projectedPoint.Z - point.Z)^2)
  159.    
  160.     -- Check if the projected point is within the line segment
  161.     local lineLength = math.sqrt(vector.X^2 + vector.Y^2 + vector.Z^2) -- Calculate the line length
  162.     local projectedDistanceToStart = math.sqrt((projectedPoint.X - lineStart.X)^2 + (projectedPoint.Y - lineStart.Y)^2 + (projectedPoint.Z - lineStart.Z)^2)
  163.     local projectedDistanceToEnd = math.sqrt((projectedPoint.X - lineEnd.X)^2 + (projectedPoint.Y - lineEnd.Y)^2 + (projectedPoint.Z - lineEnd.Z)^2)
  164.    
  165.     local withinSegment = projectedDistanceToStart <= lineLength and projectedDistanceToEnd <= lineLength
  166.    
  167.     return distance, withinSegment
  168. end
  169.  
  170.  
  171. --////////////////////////////////////////////////////
  172.  
  173. lastpos = nil
  174. lastcoin = nil
  175. tries = 0
  176. coin = nil
  177. cointable = {}
  178. count = 0
  179.  
  180. while not stop do
  181.     local succ, msg = pcall(function()
  182.  
  183.         if myplr.Character and container and container.Parent then
  184.             root = myplr.Character:FindFirstChild('HumanoidRootPart')
  185.             hum = myplr.Character:FindFirstChild('Humanoid')
  186.  
  187.             if root and hum then
  188.  
  189.                 cointable = {}
  190.                 count = 0
  191.                 coin = nil
  192.  
  193.                 for i,v in pairs(container:GetChildren()) do
  194.                     if v:FindFirstChild('Coin') then
  195.                         count = count + 1
  196.                         if table.find(COIN_TYPE, v.CoinType.Value) then
  197.                             local ele = {}
  198.                             ele.obj = v
  199.                             ele.dist1 = (v.Position - root.Position).Magnitude
  200.                             ele.dist2 = (killer and killer.Parent) and (v.Position - killer.HumanoidRootPart.Position).Magnitude or 300
  201.                             local dist3, inline
  202.                             if killer and killer.Parent then
  203.                                 dist3, inline = distanceToLine(killer.HumanoidRootPart.Position, v.Position, root.Position)
  204.                             else
  205.                                 dist3 = 300
  206.                                 inline = false
  207.                             end
  208.                             ele.dist3 = dist3
  209.                             ele.inline = inline
  210.                            
  211.                             table.insert(cointable, ele)
  212.                         end
  213.                     end
  214.                 end
  215.                
  216.                 local idk = nil
  217.                 if killer == nil then
  218.                     local mindist = 666
  219.                     for i,v in pairs(cointable) do
  220.                         if v.dist1 <= mindist then
  221.                             coin = v.obj
  222.                             mindist = v.dist1
  223.                             idk = v
  224.                         end
  225.                     end
  226.                 else
  227.                     local dangerdist = (killer ~= nil and killer.Parent ~= nil) and (root.Position - killer.HumanoidRootPart.Position).Magnitude or 300
  228.                     if dangerdist >= 60 then
  229.                         -- if killer is faraway, then get the nearest coin to us (that isnt close to the killer)
  230.                         local mindist = 666
  231.                         for i,v in pairs(cointable) do
  232.                             if v.dist3 >= 50 and not v.inline and v.dist2 >= 50 then -- we check how far the killer is from a LINE, not from a point anymore
  233.                                 if v.dist1 <= mindist then
  234.                                     coin = v.obj
  235.                                     mindist = v.dist1
  236.                                     idk = v
  237.                                 end
  238.                             end
  239.                         end
  240.                     else
  241.                         -- if killer is near, then get the furthest coin from the killer
  242.                         local maxdist = 0
  243.                         for i,v in pairs(cointable) do
  244.                             if v.dist3 + v.dist2 >= maxdist and v.dist3 >= 50 then
  245.                                 coin = v.obj
  246.                                 maxdist = v.dist3 + v.dist2
  247.                                 idk = v
  248.                             end
  249.                         end
  250.                     end
  251.                 end
  252.  
  253.                 if coin == nil then -- if still nil, then just yolo and get any closest coin
  254.                     local mindist = 666
  255.                     for i,v in pairs(cointable) do
  256.                         if v.dist1 <= mindist then
  257.                             coin = v.obj
  258.                             mindist = v.dist1
  259.                             idk = v
  260.                         end
  261.                     end
  262.                 end
  263.                 if idk then
  264.                     print(idk.dist1, idk.dist2, idk.dist3, idk.inline)
  265.                 end
  266.  
  267.                 if coin ~= nil then
  268.  
  269.                     local path,waypoints = createPath(root.Position, coin.Position)
  270.                     if path and waypoints then
  271.                         print'path waypoint'
  272.  
  273.                         clip = false
  274.                         lastpos = nil
  275.                        
  276.                         for i,waypoint in pairs(waypoints) do
  277.                             if hum.Health == 0 or root.Parent == nil or stop then break end
  278.  
  279.                             local rootpos = root.Position
  280.                             local movepos = waypoint.Position + Vector3.new(0,2.5,0)
  281.                             local movedir = (movepos - rootpos).Unit
  282.  
  283.                             tries = tries + 1
  284.                             if tries >= 4 then
  285.                                 tries = 0
  286.                                 if lastpos and (rootpos - lastpos).Magnitude < 2 then
  287.                                     if lastcoin and lastcoin == coin then
  288.                                         coin.Parent = nil -- cursed coin, cannot be collected
  289.                                         lastcoin = nil
  290.                                         break
  291.                                     end
  292.                                 end
  293.                                 lastpos = root.Position
  294.                             end
  295.                            
  296.  
  297.                             local bg = Instance.new('BodyGyro')
  298.                             bg.P = 10000
  299.                             bg.MaxTorque = Vector3.new(999999,999999,999999)
  300.                             local bp = Instance.new('BodyPosition')
  301.                             bp.P = 40000
  302.                             bp.MaxForce = Vector3.new(999999,999999,999999)
  303.  
  304.                             bp.Position = movepos
  305.                             bp.Parent = root
  306.                             bg.CFrame = CFrame.new(rootpos, movepos)
  307.                             bg.Parent = root
  308.                             wait(.15)
  309.                             bp:Destroy()
  310.                             bg:Destroy()
  311.                            
  312.                         end
  313.  
  314.                         clip = true
  315.                         lastcoin = coin
  316.                     else -- no path, then forced to fly over there
  317.                         print'no path'
  318.                        
  319.                         clip = false
  320.  
  321.                         local rootpos = root.Position
  322.                         local movepos = coin.Position + Vector3.new(0,2,0)
  323.  
  324.                         local bg = Instance.new('BodyGyro')
  325.                         bg.P = 10000
  326.                         bg.MaxTorque = Vector3.new(999999,999999,999999)
  327.                         bg.CFrame = CFrame.new(rootpos, movepos)
  328.                         bg.Parent = root
  329.                         local bv = Instance.new('BodyVelocity')
  330.                         bv.MaxForce = Vector3.new(999999,999999,999999)
  331.  
  332.                         lastpos = nil
  333.                         repeat
  334.                             tries = tries + 1
  335.                             if tries >= 4 then
  336.                                 tries = 0
  337.                                 if lastpos and (rootpos - lastpos).Magnitude < 2 then
  338.                                     if lastcoin and lastcoin == coin then
  339.                                         coin.Parent = nil -- cursed coin, cannot be collected
  340.                                         lastcoin = nil
  341.                                         break
  342.                                     end
  343.                                 end
  344.                                 lastpos = root.Position
  345.                             end
  346.                            
  347.                             bv.Velocity = (movepos - rootpos).Unit*26
  348.                             bv.Parent = root
  349.                            
  350.                             wait(.2)
  351.                         until (root.Position - rootpos).Magnitude >= (movepos - rootpos).Magnitude or hum.Health == 0 or stop
  352.                         bv:Destroy()
  353.                         bg:Destroy()
  354.  
  355.                         clip = true
  356.  
  357.                         lastcoin = coin
  358.                     end
  359.  
  360.                 else -- either we are in the lobby or that bag is full
  361.                     if not isInLobby() and count == 0 then -- make sure that the below only trigger when bag is full
  362.                         if myplr.Backpack:FindFirstChild('Knife') then
  363.                             -- reset if we're the murderer
  364.                             hum:ChangeState(Enum.HumanoidStateType.Dead)
  365.                         else
  366.                             hasgun = false
  367.                             if myplr.Backpack:FindFirstChild('Gun') then
  368.                                 hasgun = true
  369.                             else
  370.                                 if workspace:FindFirstChild('GunDrop') then
  371.                                     wait(2)
  372.                                     root.CFrame = workspace.GunDrop.CFrame
  373.                                     hasgun = true
  374.                                 end
  375.                             end
  376.  
  377.                             if hasgun and hum.Health > 0 and killer and killer.Parent then
  378.                                 -- aim at killer and wait till killer appear in sight
  379.                                 myplr.CameraMode = 'LockFirstPerson'
  380.                                 repeat
  381.                                     cam.CFrame = CFrame.new(cam.CFrame.p, killer.Head.Position)
  382.                                     wait()
  383.                                 until killerinsight() or stop or hum.Health == 0
  384.  
  385.                                 -- spam 1 until equip the gun
  386.                                 repeat
  387.                                     vim:SendKeyEvent(true, Enum.KeyCode.One, false, game)
  388.                                     vim:SendKeyEvent(false, Enum.KeyCode.One, false, game)
  389.                                     wait()
  390.                                 until myplr.Character:FindFirstChild('Gun') or stop or hum.Health == 0
  391.  
  392.                                 myplr.Character.HumanoidRootPart.CFrame = killer.HumanoidRootPart.CFrame * CFrame.new(0,0,6)
  393.                                 -- spam shoot until the game ends or we die
  394.                                 while hum.Health > 0 and killer and killer.Parent and not stop do
  395.                                     cam.CFrame = CFrame.new(cam.CFrame.p, killer.UpperTorso.Position)
  396.                                     local vp = cam.ViewportSize
  397.                                     vim:SendMouseButtonEvent(vp.X/2,vp.Y/2 , 0, true, game,1)
  398.                                     vim:SendMouseButtonEvent(vp.X/2,vp.Y/2 , 0, false, game,1)
  399.                                     run.Heartbeat:Wait()
  400.                                 end
  401.                                 myplr.CameraMode = 'Classic'
  402.                             end
  403.                         end
  404.                     end
  405.  
  406.                 end
  407.  
  408.             end
  409.         end
  410.  
  411.     end)
  412.     if not succ then warn(msg) end
  413.  
  414.     wait()
  415. end
  416. event:Disconnect()
  417. Noclip:Disconnect()
  418.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement