Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local Workspace = game:GetService("Workspace")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local RunService = game:GetService("RunService")
- local TweenService = game:GetService("TweenService")
- local UserInputService = game:GetService("UserInputService")
- local VirtualUser = game:GetService("VirtualUser")
- local localPlayer = Players.LocalPlayer
- local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
- local humanoid = character:FindFirstChildWhichIsA("Humanoid")
- local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
- local bag = localPlayer:WaitForChild("States"):WaitForChild("Bag")
- local bagSizeLevel = localPlayer:WaitForChild("Stats"):WaitForChild("BagSizeLevel"):WaitForChild("CurrentAmount")
- local robEvent = ReplicatedStorage:WaitForChild("GeneralEvents"):WaitForChild("Rob")
- local AutoFarmUI = Instance.new("ScreenGui")
- AutoFarmUI.Name = "AutoFarmUI"
- AutoFarmUI.Parent = game.CoreGui
- AutoFarmUI.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
- local MainFrame = Instance.new("Frame")
- MainFrame.Parent = AutoFarmUI
- MainFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 25)
- MainFrame.BackgroundTransparency = 0.2
- MainFrame.Position = UDim2.new(0.5, -125, 0.5, -75)
- MainFrame.Size = UDim2.new(0, 250, 0, 150)
- MainFrame.AnchorPoint = Vector2.new(0.5, 0.5)
- MainFrame.Visible = false
- local UICorner = Instance.new("UICorner")
- UICorner.CornerRadius = UDim.new(0, 10)
- UICorner.Parent = MainFrame
- local UIStroke = Instance.new("UIStroke")
- UIStroke.Thickness = 2
- UIStroke.Color = Color3.fromRGB(60, 60, 60)
- UIStroke.Parent = MainFrame
- local Title = Instance.new("TextLabel")
- Title.Parent = MainFrame
- Title.Text = "Auto Farm V4"
- Title.TextColor3 = Color3.fromRGB(255, 255, 255)
- Title.Font = Enum.Font.GothamBold
- Title.TextSize = 16
- Title.Size = UDim2.new(1, 0, 0, 30)
- Title.BackgroundTransparency = 1
- local CloseButton = Instance.new("TextButton")
- CloseButton.Parent = MainFrame
- CloseButton.Text = "X"
- CloseButton.Font = Enum.Font.GothamBold
- CloseButton.TextSize = 16
- CloseButton.TextColor3 = Color3.fromRGB(255, 0, 0)
- CloseButton.BackgroundTransparency = 1
- CloseButton.Size = UDim2.new(0, 25, 0, 25)
- CloseButton.Position = UDim2.new(0.9, 0, 0, 5)
- local ToggleButton = Instance.new("TextButton")
- ToggleButton.Parent = MainFrame
- ToggleButton.Text = "Start AutoFarm"
- ToggleButton.Font = Enum.Font.GothamBold
- ToggleButton.TextSize = 16
- ToggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
- ToggleButton.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
- ToggleButton.Size = UDim2.new(0, 200, 0, 40)
- ToggleButton.Position = UDim2.new(0, 25, 0, 70)
- local AutoFarmEnabled = false -- Flag to track the AutoFarm state
- -- Function to move the character to a target position
- local function moveToTarget(targetPosition)
- if humanoidRootPart then
- humanoidRootPart.CFrame = targetPosition
- end
- end
- -- Function to check and rob the cash registers
- local function checkCashRegister()
- for _, item in ipairs(Workspace:GetChildren()) do
- if item:IsA("Model") and item.Name == "CashRegister" then
- local openPart = item:FindFirstChild("Open")
- if openPart then
- moveToTarget(openPart.CFrame)
- robEvent:FireServer("Register", {
- Part = item:FindFirstChild("Union"),
- OpenPart = openPart,
- ActiveValue = item:FindFirstChild("Active"),
- Active = true
- })
- return true
- end
- end
- end
- return false
- end
- -- Function to check and rob safes
- local function checkSafe()
- for _, item in ipairs(Workspace:GetChildren()) do
- if item:IsA("Model") and item.Name == "Safe" and item:FindFirstChild("Amount") and item.Amount.Value > 0 then
- local safePart = item:FindFirstChild("Safe")
- if safePart then
- moveToTarget(safePart.CFrame)
- local openFlag = item:FindFirstChild("Open")
- if openFlag and openFlag.Value then
- robEvent:FireServer("Safe", item)
- else
- local openSafe = item:FindFirstChild("OpenSafe")
- if openSafe then
- openSafe:FireServer("Completed")
- end
- robEvent:FireServer("Safe", item)
- end
- return true
- end
- end
- end
- return false
- end
- -- Main loop for AutoFarming
- local function runAutoFarm()
- task.spawn(function()
- while AutoFarmEnabled do
- if not checkCashRegister() then
- checkSafe()
- end
- task.wait(1) -- Adjust the wait time as needed
- end
- end)
- end
- -- Toggle AutoFarm on/off when the button is clicked
- ToggleButton.MouseButton1Click:Connect(function()
- AutoFarmEnabled = not AutoFarmEnabled -- Toggle the flag
- if AutoFarmEnabled then
- ToggleButton.Text = "Stop AutoFarm"
- runAutoFarm() -- Start the farming process
- else
- ToggleButton.Text = "Start AutoFarm"
- -- Stop the farming process if needed
- end
- end)
- -- UI Visibility Toggle
- local function openUI()
- MainFrame.Visible = true
- MainFrame.Size = UDim2.new(0, 200, 0, 120)
- local fadeIn = TweenService:Create(MainFrame, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
- Size = UDim2.new(0, 250, 0, 150),
- BackgroundTransparency = 0.2
- })
- fadeIn:Play()
- end
- local function closeUI()
- local fadeOut = TweenService:Create(MainFrame, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
- Size = UDim2.new(0, 200, 0, 120),
- BackgroundTransparency = 1
- })
- fadeOut:Play()
- fadeOut.Completed:Connect(function()
- AutoFarmUI:Destroy()
- end)
- end
- CloseButton.MouseButton1Click:Connect(closeUI)
- openUI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement