-- Load the Rayfield UI Library local Rayfield = loadstring(game:HttpGet('https://sirius.menu/rayfield'))() -- 1. UI Configuration local Window = Rayfield:CreateWindow({ Name = "Xozich hub", LoadingTitle = "Xozich hub Loading...", LoadingSubtitle = "by Roblox_Deniska0", ConfigurationSaving = { Enabled = false, FolderName = nil, FileName = "XozichHub" }, Discord = { Enabled = false, }, KeySystem = false, KeySettings = { Title = "Untitled", Subtitle = "Key System", Note = "No method of obtaining the key is provided", FileName = "Key", SaveKey = true, Key = {"Hello"} } }) -- Create the "Auto Farm" tab local AutoFarmTab = Window:CreateTab("Auto Farm", nil) -- nil is the icon (no icon) -- Variables for loop control and thread management local isAutoFarming = false local autoFarmThread = nil -- 2 & 3. Core Functionality & Death/Respawn Protection local function autoFarmLoop() local player = game:GetService("Players").LocalPlayer while isAutoFarming do local character = player.Character local humanoid = character and character:FindFirstChildOfClass("Humanoid") local hrp = character and character:FindFirstChild("HumanoidRootPart") -- Death & Respawn Protection Check -- If the character is gone, dead, or HumanoidRootPart is missing, wait for respawn if not character or not humanoid or humanoid.Health <= 0 or not hrp then -- Wait for the player to fully respawn character = player.CharacterAdded:Wait() humanoid = character:WaitForChild("Humanoid") hrp = character:WaitForChild("HumanoidRootPart") end -- Search the entire Workspace for parts named exactly "Template" for _, obj in pairs(game.Workspace:GetDescendants()) do -- Re-check if the loop was stopped while iterating if not isAutoFarming then break end -- Also re-check health/HRP during the fast loop to prevent errors if player dies mid-iteration if not humanoid or humanoid.Health <= 0 or not hrp or not hrp.Parent then break -- Break out of the for-loop to return to the outer while-loop, triggering respawn handling end -- If the object is a BasePart and is named exactly "Template" if obj:IsA("BasePart") and obj.Name == "Template" then -- Teleport to the Template part with a 3-stud vertical offset hrp.CFrame = obj.CFrame * CFrame.new(0, 3, 0) -- 1 millisecond delay (fastest possible execution) task.wait(0.001) end end -- Small fallback wait to prevent script exhaustion if no "Template" parts are found task.wait() end end -- 4. UI Elements & Controls -- Start Auto Farm Button local StartButton = AutoFarmTab:CreateButton({ Name = "Start Auto Farm", Callback = function() -- Prevent multiple loops from running simultaneously if isAutoFarming then Rayfield:Notify({ Title = "Xozich hub", Content = "Auto Farm is already running!", Duration = 3, }) return end -- Activate flag and notify isAutoFarming = true Rayfield:Notify({ Title = "Xozich hub", Content = "Auto Farm Started!", Duration = 3, }) -- Spawn the loop in a separate thread to prevent UI freezing autoFarmThread = task.spawn(autoFarmLoop) end, }) -- Stop Auto Farm Button local StopButton = AutoFarmTab:CreateButton({ Name = "Stop Auto Farm", Callback = function() -- Only stop if it's currently running if not isAutoFarming then Rayfield:Notify({ Title = "Xozich hub", Content = "Auto Farm is not currently running!", Duration = 3, }) return end -- Disable flag and notify isAutoFarming = false Rayfield:Notify({ Title = "Xozich hub", Content = "Auto Farm Stopped!", Duration = 3, }) -- Cancel the thread immediately if autoFarmThread then task.cancel(autoFarmThread) autoFarmThread = nil end end, })