Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- MM2 Autofarm Script for VPS with CoinAura and Improved Coin Targeting
- if not game:IsLoaded() then
- game.Loaded:Wait()
- end
- task.wait(20)
- SettingsAutofarm = _G.AutofarmSettings or {AntiAfk = true, ResetWhenFullBag = true}
- _G.AutofarmSettings = SettingsAutofarm
- if _G.AutoFarmMM2IsLoaded then return end
- _G.AutoFarmMM2IsLoaded = true
- local Player = game.Players.LocalPlayer
- local Players = game.Players
- local RunService = game:GetService("RunService")
- local TweenService = game:GetService("TweenService")
- local CoinCollectedEvent = game.ReplicatedStorage.Remotes.Gameplay.CoinCollected
- local RoundStartEvent = game.ReplicatedStorage.Remotes.Gameplay.RoundStart
- local RoundEndEvent = game.ReplicatedStorage.Remotes.Gameplay.RoundEndFade
- local autofarmstopevent = Instance.new("BindableEvent")
- local function AntiAFK()
- local GC = getconnections or get_signal_cons
- if GC then
- for _, v in pairs(GC(Player.Idled)) do
- if v["Disable"] then
- v["Disable"](v)
- elseif v["Disconnect"] then
- v["Disconnect"](v)
- end
- end
- else
- local VirtualUser = cloneref(game:GetService("VirtualUser"))
- Players.LocalPlayer.Idled:Connect(function()
- VirtualUser:CaptureController()
- VirtualUser:ClickButton2(Vector2.new())
- end)
- end
- end
- local ResetWhenFullBag = SettingsAutofarm.ResetWhenFullBag
- local AutofarmIN = false
- local AutofarmStarted = true
- local CurrentCoinType = "SnowToken"
- local CoinsBeingTargeted = {}
- local function returncoincontainer()
- for _, v in workspace:GetChildren() do
- if v:FindFirstChild("CoinContainer") and v:IsA("Model") then
- return v:FindFirstChild("CoinContainer")
- end
- end
- return false
- end
- local function PcallTP(Position)
- if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
- Player.Character.HumanoidRootPart.CFrame = Position
- end
- end
- local function FindNearestCoin(container)
- if not Player.Character or not Player.Character:FindFirstChild("HumanoidRootPart") then
- warn("Player's character or HumanoidRootPart is missing!")
- return {nil, math.huge}
- end
- local coin, magn = nil, math.huge
- for _, v in pairs(container:GetChildren()) do
- if v:GetAttribute("CoinID") == CurrentCoinType and v:FindFirstChild("TouchInterest") then
- if not CoinsBeingTargeted[v] or CoinsBeingTargeted[v] == Player.Name then
- local magnitude = (Player.Character.HumanoidRootPart.Position - v.Position).Magnitude
- if magnitude < magn then
- coin = v
- magn = magnitude
- end
- end
- end
- end
- return {coin, magn}
- end
- local function UpdateCoinTarget(coin, isTargeting)
- if coin then
- if isTargeting then
- CoinsBeingTargeted[coin] = Player.Name
- else
- CoinsBeingTargeted[coin] = nil
- end
- end
- end
- local function CheckIfLocalPlayerIsMurderer()
- local items = Player.Backpack
- local character = Player.Character
- if (items and items:FindFirstChild("Knife")) or (character and character:FindFirstChild("Knife")) then
- ResetWhenFullBag = false
- return true
- else
- ResetWhenFullBag = true
- return false
- end
- end
- spawn(function()
- while true do
- if AutofarmStarted and AutofarmIN and Player.Character and returncoincontainer() then
- local coinContainer = returncoincontainer()
- local coinInfo = FindNearestCoin(coinContainer)
- if coinInfo[1] then
- local coin = coinInfo[1]
- local distance = coinInfo[2]
- -- Mark this coin as being targeted
- UpdateCoinTarget(coin, true)
- if distance > 150 then
- PcallTP(coin.CFrame)
- continue
- end
- local tween = TweenService:Create(Player.Character.HumanoidRootPart, TweenInfo.new(distance / 24, Enum.EasingStyle.Linear), {CFrame = coin.CFrame})
- tween:Play()
- firetouchinterest(Player.Character.HumanoidRootPart, coin, 0)
- autofarmstopevent.Event:Connect(function()
- tween:Cancel()
- end)
- tween.Completed:Wait()
- UpdateCoinTarget(coin, false) -- Unmark coin after reaching it
- wait(0.001)
- end
- else
- wait(0.1)
- end
- wait(0.05)
- end
- end)
- -- Restored CoinAura functionality
- spawn(function()
- while true do
- local coinContainer = returncoincontainer()
- if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") and coinContainer then
- for _, coin in pairs(coinContainer:GetChildren()) do
- if coin:FindFirstChild("TouchInterest") then
- local distance = (Player.Character.HumanoidRootPart.Position - coin.Position).Magnitude
- if distance < 5 then
- coin.CFrame = Player.Character.HumanoidRootPart.CFrame
- end
- end
- end
- end
- task.wait(0.01)
- end
- end)
- CoinCollectedEvent.OnClientEvent:Connect(function(cointype, current, max)
- AutofarmIN = true
- if cointype == CurrentCoinType and tonumber(current) == tonumber(max) then
- AutofarmIN = false
- if ResetWhenFullBag then
- Player.Character.Humanoid.Health = 0
- end
- end
- end)
- RoundStartEvent.OnClientEvent:Connect(function()
- AutofarmIN = true
- CheckIfLocalPlayerIsMurderer()
- end)
- RoundEndEvent.OnClientEvent:Connect(function()
- AutofarmIN = false
- CheckIfLocalPlayerIsMurderer() -- Reset state for the next round
- task.wait(1)
- end)
- RunService.Heartbeat:Connect(function()
- if AutofarmIN then
- CheckIfLocalPlayerIsMurderer()
- end
- end)
- AntiAFK()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement