Module is not being called

Hi there! I am having this problem where, when a function from a module is called, it won’t call it. That is a bit confusing, let me elaborate more:

So basically, when the player joins the game, a bunch of module scripts are set to run. They run perfectly fine. However, when the player dies, I need the functions to run again, otherwise they no longer work. So i use a remote event and activate the modules again. Most of them run, but some do not. The ones do not all have something in common, they all use a while true loop. So I have been trying to debug this for a long time.
This is supposed to run when the player dies. however it does not:

require(script.Game.QuestHandler):Initiate()

the required function:

local update = true

game.ReplicatedStorage.Remotes.Dead.OnClientEvent:Connect(function()
	update = false
end)

coroutine.wrap(function()
	function QuestHandler:Initiate()
		update = true
		while update == true do
			QuestHandler:CheckForUpdates()
			wait(1)
		end
	end
end)()

As you can see, I have tried a bunch of things to try and make it work. I tried placing it under a coroutine wrap, I tried disconnecting the while loop, making update false then true again.

There are no errors in the output.

i have run out of ideas of what I could try next. Any help would be appreciated.

Thanks :slight_smile:

Maybe it would be better not to use a while true loop.

Either use a different update function or put a variable so that you can control whether or not the while loop runs.

Idrk about this sort of stuff tbh.

Remove the coroutine and check the output for errors (or add prints).

Also I don’t recommend using a loop, use events instead.

1 Like