Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago

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)
0
Thank you It's been months since I've touched studio, I forgot debounce was a thing VeryDarkDev 47 — 5y
Ad

Answer this question