Advertisement
Familycade

Farming

Apr 25th, 2025 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.95 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local Workspace = game:GetService("Workspace")
  3. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4. local RunService = game:GetService("RunService")
  5. local TweenService = game:GetService("TweenService")
  6. local UserInputService = game:GetService("UserInputService")
  7. local VirtualUser = game:GetService("VirtualUser")
  8.  
  9. local localPlayer = Players.LocalPlayer
  10. local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()
  11. local humanoid = character:FindFirstChildWhichIsA("Humanoid")
  12. local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
  13.  
  14. local bag = localPlayer:WaitForChild("States"):WaitForChild("Bag")
  15. local bagSizeLevel = localPlayer:WaitForChild("Stats"):WaitForChild("BagSizeLevel"):WaitForChild("CurrentAmount")
  16. local robEvent = ReplicatedStorage:WaitForChild("GeneralEvents"):WaitForChild("Rob")
  17.  
  18. local AutoFarmUI = Instance.new("ScreenGui")
  19. AutoFarmUI.Name = "AutoFarmUI"
  20. AutoFarmUI.Parent = game.CoreGui
  21. AutoFarmUI.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  22.  
  23. local MainFrame = Instance.new("Frame")
  24. MainFrame.Parent = AutoFarmUI
  25. MainFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 25)
  26. MainFrame.BackgroundTransparency = 0.2
  27. MainFrame.Position = UDim2.new(0.5, -125, 0.5, -75)
  28. MainFrame.Size = UDim2.new(0, 250, 0, 150)
  29. MainFrame.AnchorPoint = Vector2.new(0.5, 0.5)
  30. MainFrame.Visible = false
  31.  
  32. local UICorner = Instance.new("UICorner")
  33. UICorner.CornerRadius = UDim.new(0, 10)
  34. UICorner.Parent = MainFrame
  35.  
  36. local UIStroke = Instance.new("UIStroke")
  37. UIStroke.Thickness = 2
  38. UIStroke.Color = Color3.fromRGB(60, 60, 60)
  39. UIStroke.Parent = MainFrame
  40.  
  41. local Title = Instance.new("TextLabel")
  42. Title.Parent = MainFrame
  43. Title.Text = "Auto Farm V4"
  44. Title.TextColor3 = Color3.fromRGB(255, 255, 255)
  45. Title.Font = Enum.Font.GothamBold
  46. Title.TextSize = 16
  47. Title.Size = UDim2.new(1, 0, 0, 30)
  48. Title.BackgroundTransparency = 1
  49.  
  50. local CloseButton = Instance.new("TextButton")
  51. CloseButton.Parent = MainFrame
  52. CloseButton.Text = "X"
  53. CloseButton.Font = Enum.Font.GothamBold
  54. CloseButton.TextSize = 16
  55. CloseButton.TextColor3 = Color3.fromRGB(255, 0, 0)
  56. CloseButton.BackgroundTransparency = 1
  57. CloseButton.Size = UDim2.new(0, 25, 0, 25)
  58. CloseButton.Position = UDim2.new(0.9, 0, 0, 5)
  59.  
  60. local ToggleButton = Instance.new("TextButton")
  61. ToggleButton.Parent = MainFrame
  62. ToggleButton.Text = "Start AutoFarm"
  63. ToggleButton.Font = Enum.Font.GothamBold
  64. ToggleButton.TextSize = 16
  65. ToggleButton.TextColor3 = Color3.fromRGB(255, 255, 255)
  66. ToggleButton.BackgroundColor3 = Color3.fromRGB(0, 170, 0)
  67. ToggleButton.Size = UDim2.new(0, 200, 0, 40)
  68. ToggleButton.Position = UDim2.new(0, 25, 0, 70)
  69.  
  70. local AutoFarmEnabled = false -- Flag to track the AutoFarm state
  71.  
  72. -- Function to move the character to a target position
  73. local function moveToTarget(targetPosition)
  74. if humanoidRootPart then
  75. humanoidRootPart.CFrame = targetPosition
  76. end
  77. end
  78.  
  79. -- Function to check and rob the cash registers
  80. local function checkCashRegister()
  81. for _, item in ipairs(Workspace:GetChildren()) do
  82. if item:IsA("Model") and item.Name == "CashRegister" then
  83. local openPart = item:FindFirstChild("Open")
  84. if openPart then
  85. moveToTarget(openPart.CFrame)
  86. robEvent:FireServer("Register", {
  87. Part = item:FindFirstChild("Union"),
  88. OpenPart = openPart,
  89. ActiveValue = item:FindFirstChild("Active"),
  90. Active = true
  91. })
  92. return true
  93. end
  94. end
  95. end
  96. return false
  97. end
  98.  
  99. -- Function to check and rob safes
  100. local function checkSafe()
  101. for _, item in ipairs(Workspace:GetChildren()) do
  102. if item:IsA("Model") and item.Name == "Safe" and item:FindFirstChild("Amount") and item.Amount.Value > 0 then
  103. local safePart = item:FindFirstChild("Safe")
  104. if safePart then
  105. moveToTarget(safePart.CFrame)
  106. local openFlag = item:FindFirstChild("Open")
  107. if openFlag and openFlag.Value then
  108. robEvent:FireServer("Safe", item)
  109. else
  110. local openSafe = item:FindFirstChild("OpenSafe")
  111. if openSafe then
  112. openSafe:FireServer("Completed")
  113. end
  114. robEvent:FireServer("Safe", item)
  115. end
  116. return true
  117. end
  118. end
  119. end
  120. return false
  121. end
  122.  
  123. -- Main loop for AutoFarming
  124. local function runAutoFarm()
  125. task.spawn(function()
  126. while AutoFarmEnabled do
  127. if not checkCashRegister() then
  128. checkSafe()
  129. end
  130. task.wait(1) -- Adjust the wait time as needed
  131. end
  132. end)
  133. end
  134.  
  135. -- Toggle AutoFarm on/off when the button is clicked
  136. ToggleButton.MouseButton1Click:Connect(function()
  137. AutoFarmEnabled = not AutoFarmEnabled -- Toggle the flag
  138. if AutoFarmEnabled then
  139. ToggleButton.Text = "Stop AutoFarm"
  140. runAutoFarm() -- Start the farming process
  141. else
  142. ToggleButton.Text = "Start AutoFarm"
  143. -- Stop the farming process if needed
  144. end
  145. end)
  146.  
  147. -- UI Visibility Toggle
  148. local function openUI()
  149. MainFrame.Visible = true
  150. MainFrame.Size = UDim2.new(0, 200, 0, 120)
  151. local fadeIn = TweenService:Create(MainFrame, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {
  152. Size = UDim2.new(0, 250, 0, 150),
  153. BackgroundTransparency = 0.2
  154. })
  155. fadeIn:Play()
  156. end
  157.  
  158. local function closeUI()
  159. local fadeOut = TweenService:Create(MainFrame, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
  160. Size = UDim2.new(0, 200, 0, 120),
  161. BackgroundTransparency = 1
  162. })
  163. fadeOut:Play()
  164. fadeOut.Completed:Connect(function()
  165. AutoFarmUI:Destroy()
  166. end)
  167. end
  168.  
  169. CloseButton.MouseButton1Click:Connect(closeUI)
  170. openUI()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement