Advertisement
suramraja1

EmEm2

Apr 8th, 2024 (edited)
1,547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.03 KB | None | 0 0
  1. -- MM2 Autofarm Script for VPS with CoinAura and Improved Coin Targeting
  2. if not game:IsLoaded() then
  3.     game.Loaded:Wait()
  4. end
  5.  
  6. task.wait(20)
  7.  
  8. SettingsAutofarm = _G.AutofarmSettings or {AntiAfk = true, ResetWhenFullBag = true}
  9. _G.AutofarmSettings = SettingsAutofarm
  10. if _G.AutoFarmMM2IsLoaded then return end
  11. _G.AutoFarmMM2IsLoaded = true
  12.  
  13. local Player = game.Players.LocalPlayer
  14. local Players = game.Players
  15. local RunService = game:GetService("RunService")
  16. local TweenService = game:GetService("TweenService")
  17.  
  18. local CoinCollectedEvent = game.ReplicatedStorage.Remotes.Gameplay.CoinCollected
  19. local RoundStartEvent = game.ReplicatedStorage.Remotes.Gameplay.RoundStart
  20. local RoundEndEvent = game.ReplicatedStorage.Remotes.Gameplay.RoundEndFade
  21. local autofarmstopevent = Instance.new("BindableEvent")
  22.  
  23. local function AntiAFK()
  24.     local GC = getconnections or get_signal_cons
  25.     if GC then
  26.         for _, v in pairs(GC(Player.Idled)) do
  27.             if v["Disable"] then
  28.                 v["Disable"](v)
  29.             elseif v["Disconnect"] then
  30.                 v["Disconnect"](v)
  31.             end
  32.         end
  33.     else
  34.         local VirtualUser = cloneref(game:GetService("VirtualUser"))
  35.         Players.LocalPlayer.Idled:Connect(function()
  36.             VirtualUser:CaptureController()
  37.             VirtualUser:ClickButton2(Vector2.new())
  38.         end)
  39.     end
  40. end
  41.  
  42. local ResetWhenFullBag = SettingsAutofarm.ResetWhenFullBag
  43. local AutofarmIN = false
  44. local AutofarmStarted = true
  45. local CurrentCoinType = "SnowToken"
  46. local CoinsBeingTargeted = {}
  47.  
  48. local function returncoincontainer()
  49.     for _, v in workspace:GetChildren() do
  50.         if v:FindFirstChild("CoinContainer") and v:IsA("Model") then
  51.             return v:FindFirstChild("CoinContainer")
  52.         end
  53.     end
  54.     return false
  55. end
  56.  
  57. local function PcallTP(Position)
  58.     if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
  59.         Player.Character.HumanoidRootPart.CFrame = Position
  60.     end
  61. end
  62.  
  63. local function FindNearestCoin(container)
  64.     if not Player.Character or not Player.Character:FindFirstChild("HumanoidRootPart") then
  65.         warn("Player's character or HumanoidRootPart is missing!")
  66.         return {nil, math.huge}
  67.     end
  68.  
  69.     local coin, magn = nil, math.huge
  70.     for _, v in pairs(container:GetChildren()) do
  71.         if v:GetAttribute("CoinID") == CurrentCoinType and v:FindFirstChild("TouchInterest") then
  72.             if not CoinsBeingTargeted[v] or CoinsBeingTargeted[v] == Player.Name then
  73.                 local magnitude = (Player.Character.HumanoidRootPart.Position - v.Position).Magnitude
  74.                 if magnitude < magn then
  75.                     coin = v
  76.                     magn = magnitude
  77.                 end
  78.             end
  79.         end
  80.     end
  81.     return {coin, magn}
  82. end
  83.  
  84. local function UpdateCoinTarget(coin, isTargeting)
  85.     if coin then
  86.         if isTargeting then
  87.             CoinsBeingTargeted[coin] = Player.Name
  88.         else
  89.             CoinsBeingTargeted[coin] = nil
  90.         end
  91.     end
  92. end
  93.  
  94. local function CheckIfLocalPlayerIsMurderer()
  95.     local items = Player.Backpack
  96.     local character = Player.Character
  97.  
  98.     if (items and items:FindFirstChild("Knife")) or (character and character:FindFirstChild("Knife")) then
  99.         ResetWhenFullBag = false
  100.         return true
  101.     else
  102.         ResetWhenFullBag = true
  103.         return false
  104.     end
  105. end
  106.  
  107. spawn(function()
  108.     while true do
  109.         if AutofarmStarted and AutofarmIN and Player.Character and returncoincontainer() then
  110.             local coinContainer = returncoincontainer()
  111.             local coinInfo = FindNearestCoin(coinContainer)
  112.             if coinInfo[1] then
  113.                 local coin = coinInfo[1]
  114.                 local distance = coinInfo[2]
  115.  
  116.                 -- Mark this coin as being targeted
  117.                 UpdateCoinTarget(coin, true)
  118.  
  119.                 if distance > 150 then
  120.                     PcallTP(coin.CFrame)
  121.                     continue
  122.                 end
  123.  
  124.                 local tween = TweenService:Create(Player.Character.HumanoidRootPart, TweenInfo.new(distance / 24, Enum.EasingStyle.Linear), {CFrame = coin.CFrame})
  125.                 tween:Play()
  126.                 firetouchinterest(Player.Character.HumanoidRootPart, coin, 0)
  127.                 autofarmstopevent.Event:Connect(function()
  128.                     tween:Cancel()
  129.                 end)
  130.  
  131.                 tween.Completed:Wait()
  132.                 UpdateCoinTarget(coin, false) -- Unmark coin after reaching it
  133.  
  134.                 wait(0.001)
  135.             end
  136.         else
  137.             wait(0.1)
  138.         end
  139.         wait(0.05)
  140.     end
  141. end)
  142.  
  143. -- Restored CoinAura functionality
  144. spawn(function()
  145.     while true do
  146.         local coinContainer = returncoincontainer()
  147.         if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") and coinContainer then
  148.             for _, coin in pairs(coinContainer:GetChildren()) do
  149.                 if coin:FindFirstChild("TouchInterest") then
  150.                     local distance = (Player.Character.HumanoidRootPart.Position - coin.Position).Magnitude
  151.                     if distance < 5 then
  152.                         coin.CFrame = Player.Character.HumanoidRootPart.CFrame
  153.                     end
  154.                 end
  155.             end
  156.         end
  157.         task.wait(0.01)
  158.     end
  159. end)
  160.  
  161. CoinCollectedEvent.OnClientEvent:Connect(function(cointype, current, max)
  162.     AutofarmIN = true
  163.     if cointype == CurrentCoinType and tonumber(current) == tonumber(max) then
  164.         AutofarmIN = false
  165.         if ResetWhenFullBag then
  166.             Player.Character.Humanoid.Health = 0
  167.         end
  168.     end
  169. end)
  170.  
  171. RoundStartEvent.OnClientEvent:Connect(function()
  172.     AutofarmIN = true
  173.     CheckIfLocalPlayerIsMurderer()
  174. end)
  175.  
  176. RoundEndEvent.OnClientEvent:Connect(function()
  177.     AutofarmIN = false
  178.     CheckIfLocalPlayerIsMurderer() -- Reset state for the next round
  179.     task.wait(1)
  180. end)
  181.  
  182. RunService.Heartbeat:Connect(function()
  183.     if AutofarmIN then
  184.         CheckIfLocalPlayerIsMurderer()
  185.     end
  186. end)
  187.  
  188. AntiAFK()
  189.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement