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

How can I make a tool only fire an event once?

Title was hard to make and may not be descriptive enough but

I have a tool that when activated will fire an event which plays an animation

However the play can spam this

local Tool = script.Parent 
local pwr = 0.1
local mowevent = game:GetService("ReplicatedStorage").Remote.Mow


Tool.Activated:Connect(function()

		
	mowevent:FireServer(pwr)
	Tool.Enabled = false	
	wait(1)
	Tool.Enabled = true
end)

1 answer

✓ Accepted answer

###Add a debounce. Debounce can delay code, or just stop it, depending on how you use it.

local tool = script.Parent
local debounce = false

tool.Activated:Connect(function()
    if not debounce then
        debounce = true
        mowevent:FireServer(pwr)
    end
end)

1 comment

0

Thank you It's been months since I've touched studio, I forgot debounce was a thing

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