Guest User

Untitled

a guest
Apr 20th, 2026
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.89 KB | None | 0 0
  1.  
  2.  
  3. local Players = game:GetService("Players")
  4. local RunService = game:GetService("RunService")
  5. local CollectionService = game:GetService("CollectionService")
  6. local UserInputService = game:GetService("UserInputService")
  7.  
  8.  
  9. local player = game:GetService("Players").LocalPlayer
  10. if not player.Character then player.CharacterAdded:Wait() end
  11.  
  12.  
  13. local running = false
  14. local tweenSpeed = 100
  15. local moverConn = nil
  16.  
  17.  
  18. -- ── Get the REAL root (non-massless, direct child of character) ──
  19. local function getHRP()
  20. local char = player.Character
  21. if not char then return nil end
  22. for _, v in ipairs(char:GetChildren()) do
  23. if v.Name == "RootPart" and v:IsA("BasePart") and not v.Massless then
  24. return v
  25. end
  26. end
  27. return char.PrimaryPart
  28. end
  29.  
  30.  
  31. local function getClosestFood()
  32. local hrp = getHRP()
  33. if not hrp then return nil end
  34. local best, bestDist = nil, math.huge
  35. for _, food in CollectionService:GetTagged("Food") do
  36. if not food or not food.Parent then continue end
  37. local ok, pos = pcall(function()
  38. if food:IsA("Model") then return food:GetPivot().Position
  39. elseif food:IsA("BasePart") then return food.Position end
  40. end)
  41. if ok and pos then
  42. local d = (hrp.Position - pos).Magnitude
  43. if d < bestDist then
  44. bestDist = d
  45. best = { instance = food, position = pos }
  46. end
  47. end
  48. end
  49. return best
  50. end
  51.  
  52.  
  53. local function stopMover()
  54. if moverConn then moverConn:Disconnect(); moverConn = nil end
  55. end
  56.  
  57.  
  58. local function moveTo(targetPos)
  59. local reached = false
  60. stopMover()
  61. moverConn = RunService.Heartbeat:Connect(function(dt)
  62. local hrp = getHRP()
  63. if not hrp or not running then reached = true; stopMover(); return end
  64. local diff = targetPos - hrp.Position
  65. local dist = diff.Magnitude
  66. if dist < 2 then reached = true; stopMover(); return end
  67. local step = math.min(tweenSpeed * dt, dist)
  68. hrp.CFrame = CFrame.new(hrp.Position + diff.Unit * step)
  69. end)
  70. while not reached do task.wait(0.05) end
  71. end
  72.  
  73.  
  74. -- ── GUI ──────────────────────────────────────────────────────────
  75. local gui = Instance.new("ScreenGui")
  76. gui.Name = "FoodCollector"
  77. gui.ResetOnSpawn = false
  78. gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
  79. gui.Parent = player:WaitForChild("PlayerGui")
  80.  
  81.  
  82. local panel = Instance.new("Frame")
  83. panel.Size = UDim2.new(0, 270, 0, 215)
  84. panel.Position = UDim2.new(0.5, -135, 0.5, -107)
  85. panel.BackgroundColor3 = Color3.fromRGB(18, 18, 28)
  86. panel.BorderSizePixel = 0
  87. panel.Active = true
  88. panel.Draggable = true
  89. panel.Parent = gui
  90. Instance.new("UICorner", panel).CornerRadius = UDim.new(0, 10)
  91.  
  92.  
  93. local stroke = Instance.new("UIStroke", panel)
  94. stroke.Color = Color3.fromRGB(80, 80, 130)
  95. stroke.Thickness = 1.5
  96.  
  97.  
  98. local titleBar = Instance.new("Frame", panel)
  99. titleBar.Size = UDim2.new(1, 0, 0, 38)
  100. titleBar.BackgroundColor3 = Color3.fromRGB(35, 35, 58)
  101. titleBar.BorderSizePixel = 0
  102. Instance.new("UICorner", titleBar).CornerRadius = UDim.new(0, 10)
  103.  
  104.  
  105. local titlePatch = Instance.new("Frame", titleBar)
  106. titlePatch.Size = UDim2.new(1, 0, 0, 10)
  107. titlePatch.Position = UDim2.new(0, 0, 1, -10)
  108. titlePatch.BackgroundColor3 = Color3.fromRGB(35, 35, 58)
  109. titlePatch.BorderSizePixel = 0
  110.  
  111.  
  112. local titleLbl = Instance.new("TextLabel", titleBar)
  113. titleLbl.Size = UDim2.new(1, -50, 1, 0)
  114. titleLbl.Position = UDim2.new(0, 12, 0, 0)
  115. titleLbl.BackgroundTransparency = 1
  116. titleLbl.Text = " Food Collector"
  117. titleLbl.TextColor3 = Color3.fromRGB(230, 230, 255)
  118. titleLbl.TextSize = 15
  119. titleLbl.Font = Enum.Font.GothamBold
  120. titleLbl.TextXAlignment = Enum.TextXAlignment.Left
  121.  
  122.  
  123. local closeBtn = Instance.new("TextButton", titleBar)
  124. closeBtn.Size = UDim2.new(0, 26, 0, 26)
  125. closeBtn.Position = UDim2.new(1, -32, 0.5, -13)
  126. closeBtn.BackgroundColor3 = Color3.fromRGB(190, 50, 50)
  127. closeBtn.Text = "✕"
  128. closeBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
  129. closeBtn.TextSize = 13
  130. closeBtn.Font = Enum.Font.GothamBold
  131. closeBtn.BorderSizePixel = 0
  132. Instance.new("UICorner", closeBtn).CornerRadius = UDim.new(0, 6)
  133.  
  134.  
  135. local statusLbl = Instance.new("TextLabel", panel)
  136. statusLbl.Size = UDim2.new(1, -20, 0, 22)
  137. statusLbl.Position = UDim2.new(0, 10, 0, 46)
  138. statusLbl.BackgroundTransparency = 1
  139. statusLbl.Text = "Status: Idle"
  140. statusLbl.TextColor3 = Color3.fromRGB(150, 150, 180)
  141. statusLbl.TextSize = 13
  142. statusLbl.Font = Enum.Font.Gotham
  143. statusLbl.TextXAlignment = Enum.TextXAlignment.Left
  144.  
  145.  
  146. local countLbl = Instance.new("TextLabel", panel)
  147. countLbl.Size = UDim2.new(1, -20, 0, 18)
  148. countLbl.Position = UDim2.new(0, 10, 0, 68)
  149. countLbl.BackgroundTransparency = 1
  150. countLbl.Text = "Food in world: 0"
  151. countLbl.TextColor3 = Color3.fromRGB(120, 120, 160)
  152. countLbl.TextSize = 12
  153. countLbl.Font = Enum.Font.Gotham
  154. countLbl.TextXAlignment = Enum.TextXAlignment.Left
  155.  
  156.  
  157. local speedLbl = Instance.new("TextLabel", panel)
  158. speedLbl.Size = UDim2.new(1, -20, 0, 20)
  159. speedLbl.Position = UDim2.new(0, 10, 0, 94)
  160. speedLbl.BackgroundTransparency = 1
  161. speedLbl.Text = "Speed: 100 studs/s"
  162. speedLbl.TextColor3 = Color3.fromRGB(150, 150, 180)
  163. speedLbl.TextSize = 13
  164. speedLbl.Font = Enum.Font.Gotham
  165. speedLbl.TextXAlignment = Enum.TextXAlignment.Left
  166.  
  167.  
  168. local track = Instance.new("Frame", panel)
  169. track.Size = UDim2.new(1, -20, 0, 8)
  170. track.Position = UDim2.new(0, 10, 0, 122)
  171. track.BackgroundColor3 = Color3.fromRGB(50, 50, 75)
  172. track.BorderSizePixel = 0
  173. Instance.new("UICorner", track).CornerRadius = UDim.new(1, 0)
  174.  
  175.  
  176. local fill = Instance.new("Frame", track)
  177. fill.Size = UDim2.new(tweenSpeed / 1000, 0, 1, 0)
  178. fill.BackgroundColor3 = Color3.fromRGB(90, 160, 255)
  179. fill.BorderSizePixel = 0
  180. Instance.new("UICorner", fill).CornerRadius = UDim.new(1, 0)
  181.  
  182.  
  183. local knob = Instance.new("TextButton", track)
  184. knob.Size = UDim2.new(0, 20, 0, 20)
  185. knob.Position = UDim2.new(tweenSpeed / 1000, -10, 0.5, -10)
  186. knob.BackgroundColor3 = Color3.fromRGB(220, 220, 255)
  187. knob.Text = ""
  188. knob.BorderSizePixel = 0
  189. Instance.new("UICorner", knob).CornerRadius = UDim.new(1, 0)
  190.  
  191.  
  192. local sliderDragging = false
  193. knob.MouseButton1Down:Connect(function() sliderDragging = true end)
  194. UserInputService.InputEnded:Connect(function(inp)
  195. if inp.UserInputType == Enum.UserInputType.MouseButton1 then
  196. sliderDragging = false
  197. end
  198. end)
  199. UserInputService.InputChanged:Connect(function(inp)
  200. if not sliderDragging then return end
  201. if inp.UserInputType ~= Enum.UserInputType.MouseMovement then return end
  202. local ratio = math.clamp((inp.Position.X - track.AbsolutePosition.X) / track.AbsoluteSize.X, 0, 1)
  203. tweenSpeed = math.max(1, math.floor(ratio * 1000))
  204. fill.Size = UDim2.new(ratio, 0, 1, 0)
  205. knob.Position = UDim2.new(ratio, -10, 0.5, -10)
  206. speedLbl.Text = "Speed: " .. tweenSpeed .. " studs/s"
  207. end)
  208.  
  209.  
  210. local function makeBtn(text, color, xOffset)
  211. local btn = Instance.new("TextButton", panel)
  212. btn.Size = UDim2.new(0, 112, 0, 36)
  213. btn.Position = UDim2.new(0, xOffset, 0, 162)
  214. btn.BackgroundColor3 = color
  215. btn.Text = text
  216. btn.TextColor3 = Color3.fromRGB(255, 255, 255)
  217. btn.TextSize = 14
  218. btn.Font = Enum.Font.GothamBold
  219. btn.BorderSizePixel = 0
  220. Instance.new("UICorner", btn).CornerRadius = UDim.new(0, 8)
  221. return btn
  222. end
  223.  
  224.  
  225. local startBtn = makeBtn(" Start", Color3.fromRGB(40, 165, 70), 16)
  226. local stopBtn = makeBtn("■ Stop", Color3.fromRGB(185, 50, 50), 142)
  227.  
  228.  
  229. -- ── Loop ─────────────────────────────────────────────────────────
  230. local function setStatus(msg, color)
  231. statusLbl.Text = "Status: " .. msg
  232. statusLbl.TextColor3 = color or Color3.fromRGB(150, 150, 180)
  233. end
  234.  
  235.  
  236. local function collectLoop()
  237. while running do
  238. if not player.Character then
  239. player.CharacterAdded:Wait()
  240. task.wait(1)
  241. continue
  242. end
  243.  
  244.  
  245. local hrp = getHRP()
  246. if not hrp then
  247. setStatus("No RootPart...", Color3.fromRGB(200, 100, 100))
  248. task.wait(1)
  249. continue
  250. end
  251.  
  252.  
  253. countLbl.Text = "Food in world: " .. #CollectionService:GetTagged("Food")
  254.  
  255.  
  256. local food = getClosestFood()
  257. if not food or not food.instance or not food.instance.Parent then
  258. setStatus("No food nearby...", Color3.fromRGB(200, 180, 80))
  259. task.wait(0.3)
  260. continue
  261. end
  262.  
  263.  
  264. setStatus("Going to " .. food.instance.Name, Color3.fromRGB(90, 200, 90))
  265. moveTo(food.position)
  266. end
  267. setStatus("Stopped")
  268. end
  269.  
  270.  
  271. startBtn.MouseButton1Click:Connect(function()
  272. if running then return end
  273. running = true
  274. setStatus("Running", Color3.fromRGB(90, 200, 90))
  275. task.spawn(collectLoop)
  276. end)
  277.  
  278.  
  279. stopBtn.MouseButton1Click:Connect(function()
  280. running = false
  281. stopMover()
  282. setStatus("Stopped")
  283. end)
  284.  
  285.  
  286. closeBtn.MouseButton1Click:Connect(function()
  287. running = false
  288. stopMover()
  289. gui:Destroy()
  290. end)
  291.  
  292.  
  293. setStatus("Idle")
  294.  
  295.  
  296.  
Advertisement
Add Comment
Please, Sign In to add comment