Scripts in a tool

Hello! I’m trying to make it so when a player equips a tool a certain script will execute once I currently have this:

tool.Equipped:Connect(function(mouse)

	print("EMF Equipped")
	wait (.1)

end)

this works perfectly fine, although a player can spam unequip/requip a tool and it’ll run the script multiple times/break it or spam output with the print.

How would I go by making sure this script will ‘disable’ and then ‘reset’ when a player requips?

For example:

If I had a countdown that executes during it and a player unequiped it, it’d reset the script and start back from ‘1’

Any help is appreciated, thank you!

Add a debounce:

local debounce = true

tool.Equipped:Connect(function(mouse)
if debounce == true then
debounce = false
print(“EMF Equipped”)
wait (1)
debounce = true
end

end)

2 Likes