Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Can a ModuleScript continue to run even though its been destroyed?

Asked by
Nixvoid 12
5 years ago

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)

1 answer

Log in to vote
-1
Answered by 5 years ago

Theee module script is effectively copied into the script that requires it, so you want to stop the function when that button is pressed.

0
No it's not? User#19524 175 — 5y
0
i dont mead literally copied but doesnt the table you return in the module live on in the requiring script after the modules been deleted radusavin366 617 — 5y
0
mean* radusavin366 617 — 5y
0
Well, your answer somewhat helped in a way I guess, not sure if it was truly the answer that aided me to fix my payout system. Anyway, thanks for bringing your attention to my post. Nixvoid 12 — 5y
Ad

Answer this question