Categories > Coding > Lua >

how to make this autofarm work

OyAdonis

Owner of Xenon [BETA]

vip

Posts: 167

Threads: 18

Joined: Mar, 2022

Reputation: -19

Posted

with this autofarm toggle, when i enable it, it autofarms but when i disable the toggle it doesnt stop 

 

the game its for: https://www.roblox.com/games/11939099110/2x-Ski-Race

the script: 

 

  local AutoFarm = false

 

 function powerfarming()

   local RemoteEvent = game:GetService("ReplicatedStorage").Remote.Event.Game["[C-S]PlayerPickCoin"]

   print("powerfarming function called")  -- Add a print statement to confirm the function is being called

 

   while true do

      for i = 1, 5 do

         RemoteEvent:FireServer()

      end

      wait(1/30)

   end

end

  

 local AutoFarmToggle = LP:CreateToggle({

    Name = "Autofarm Wins",

    CurrentValue = false,

    Flag = "AFW",

    Callback = function(Value)

       AutoFarm = Value

       if AutoFarm then

          powerfarming()

       end

    end,

 })

 

edit: this worked 

 

local AutoFarm = false

local powerfarmingLoop

 

function powerfarming()

   local RemoteEvent = game:GetService("ReplicatedStorage").Remote.Event.Game["[C-S]PlayerPickCoin"]

   print("powerfarming function called")

   

   while AutoFarm do

      for i = 1, 5 do

         RemoteEvent:FireServer()

      end

      wait(1/30)

   end

   powerfarmingLoop = nil

end

  

local AutoFarmToggle = LP:CreateToggle({

    Name = "Autofarm Wins",

    CurrentValue = false,

    Flag = "AFW",

    Callback = function(Value)

       AutoFarm = Value

       if AutoFarm then

          if not powerfarmingLoop then

            powerfarmingLoop = coroutine.wrap(powerfarming)

            powerfarmingLoop()

          end

       else

          if powerfarmingLoop then

            powerfarmingLoop = nil

          end

       end

    end,

})

  • 0

professional exploiter

Users viewing this thread:

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