Categories > Exploiting > Roblox >

How do I get this to loop forever

Posts: 4

Threads: 4

Joined: Dec, 2023

Reputation: 0

Posted

Im working on an autofarm that will teleport to chests and then pick them up, the chests are all named different things and so i have to use :GetChildren, 

The problem is it will get all the chests that are currently there and once they have all been picked up it will give me an error.

ChestToggle:OnChanged(function()
        while Options.ChestFarm.Value == true do
            local ChestsAvaliable = game:GetService("Workspace").chests:GetChildren()

            for i = 1, #ChestsAvaliable do
                if Options.ChestFarm.Value == true then
                    local child = ChestsAvaliable[i]

                    if child == nil then return end
                    local Chest = game:GetService("Workspace").chests:FindFirstChild(child.Name)
                    local Prompt = Chest:WaitForChild("ProximityPrompt")   
                                        
                    game.Players.LocalPlayer.Character.HumanoidRootPart.Position = Chest.Position
                    wait(0.5)
                    Prompt.HoldDuration = 0
                    fireproximityprompt(Prompt, 1, 100)
                end
            end
        end
    end)
  • 0

Posts: 1

Threads: 0

Joined: May, 2024

Reputation: 0

Replied

It looks like you're working on an autofarm script for a game that involves teleporting to chests and picking them up. You're using the `:GetChildren` method to find all the chests with different names. However, you're encountering an error once all the chests have been picked up.

 

One potential issue is that the script doesn't stop when there are no more chests available, causing it to continue running and eventually causing an error. To fix this, you can add a check to stop the script when there are no more chests left to pick up.

 

Here's how you can modify your script:

 

```lua

ChestToggle:OnChanged(function()

    while Options.ChestFarm.Value == true do

        local ChestsAvailable = game:GetService("Workspace").chests:GetChildren()

 

        if #ChestsAvailable == 0 then

            -- No more chests available, so exit the loop

            break

        end

 

        for i = 1, #ChestsAvailable do

            if Options.ChestFarm.Value == true then

                local child = ChestsAvailable[i]

 

                if child == nil then return end

                local Chest = game:GetService("Workspace").chests:FindFirstChild(child.Name)

                local Prompt = Chest:WaitForChild("ProximityPrompt")   

                                    

                game.Players.LocalPlayer.Character.HumanoidRootPart.Position = Chest.Position

                wait(0.5)

                Prompt.HoldDuration = 0

                fireproximityprompt(Prompt, 1, 100)

            end

        end

    end

end)

```

 

In this modified version, the script checks if there are no more chests available (`#ChestsAvailable == 0`) and exits the loop if that's the case. This prevents the script from running into errors when there are no chests left to pick up.

  • 0

Posts: 4

Threads: 0

Joined: Apr, 2024

Reputation: 0

Replied

Thanks for answering.

  • 0

Users viewing this thread:

( Members: 0, Guests: 2, Total: 2 )