Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

4 comments

0

No it's not?

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

0

mean*

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.