I need help with threads in my module script (gif examples added)

Hi! :wave:
I recently made a module script for my notification system that has 1 function in it

-- the module
function module.notify(frame,character,tag)
	if (cs:HasTag(character,tag)) then return end -- this is a debounce
	cs:AddTag(character,tag)
	-- code that tweens the frame on the screen to notify the player goes here
	wait(n)
	cs:RemoveTag(character,tag) -- so that the notification can work again
end

-- localscript that calls the module
uis.InputBegan:Connect(function(input,processed)
	if (processed) then return end
	if input.UserInputType == Enum.UserInputType.Keyboard then
		if input.KeyCode == Enum.KeyCode.Q then
			spawn(function()
			    module.notify(frame,character,"lowmana")
			end)
		end
	end
end)

It works perfect when I trigger it with the input, but when i’m activating it while clicking with a tool it causes everything to mess up and the notification gets spammed!, I checked inside the tool script, nothing is removing any tags. This is confusing :confused:
(I used cntl H to search for the word ‘tag’ it’s not even in the tool script) Idk what’s going on, I create a new thread so that it doesn’t yield the current thread.

1 Like