How to Create Tools and Animate Them [TUTORIAL]

Sorry to nitpick a tutorial, but I feel it’s really important to say: please avoid using wait(n) for debounces, it’s very inconsistent and in a laggier game (or wherever wait(n) decides to throttle), may result in significant delays to when the wait(n) finishes, meaning players can be at a disadvantage depending on the performance of the function.

Instead, we can use the (currently) most accurate ‘real-time’ function: os.clock(), like this:

local nextActivate = os.clock()
local debounceTime = 1

tool.Activated:Connect(function()
    if os.clock() > nextActivate then
        nextActivate = os.clock() + debounceTime

        animationTrack:Play()
    end
end

TL;DR: wait executes inconsistently and is subject to lag, which is not great game design, therefore you should use the time in real-time compared to the last time, and it will work pretty much perfectly reliably.

24 Likes