I have made a ModuleScript (which is used for payouts) which runs on a 'while true do' loop and every minute it adds a specified number to the existing number in both the player's leaderstats and to the player's cash display simultaneously.
This whole system is tied to a job system, within the job system there is also a button which when pressed, it causes you to leave the current job and is supposed to remove the payout script. However, when it is pressed the payout continues to run even though the folder it is in gets destroyed.
Here is the code for the payout script:
local module = {game.Players:FindFirstChildOfClass("Player").Jobs.CandyShopWorker} payCheckAmount = 12 local function CandyShopWorkerPayout() module[1].Value = true if script.Parent.Parent.ModuleOriginals.CandyShopWorkerPayout.IsThereAlreadyAPayout.Value == true then while true do wait(60) game.Players:FindFirstChildOfClass("Player").leaderstats.BloxCoins.Value = game.Players:FindFirstChildOfClass("Player").leaderstats.BloxCoins.Value+payCheckAmount game.Players:FindFirstChildOfClass("Player").PlayerGui.BloxCoinsUI.bloxcoinsUIFrame.currencyAmount.Text = game.Players:FindFirstChildOfClass("Player").leaderstats.BloxCoins.Value end else print("payout exists, no payout being paid out...badum tsss") end end CandyShopWorkerPayout() return module
(Just click view source if any parts of the code are cut out and whatnot)
Theee module script is effectively copied into the script that requires it, so you want to stop the function when that button is pressed.