How would I go about charging system for my tool?

Hi, so I’ve been trying to make a hammer that has to charge before being able to smash/strike. If that makes sense.

Here’s my attempt so far and the animations sometimes work and sometimes not.

local tool = script.Parent

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local charge = script.Charge
local smash = script.Smash

local chargeTrack = humanoid:LoadAnimation(charge)
local smashTrack = humanoid:LoadAnimation(smash)

local charging = false
local charged = false

tool.Activated:Connect(function()
    chargeTrack:Play()
    
    if not charging then
        charging = true
        
        wait(2.9) --chargeTrack is 3 seconds long, that's why.
        chargeTrack:AdjustSpeed(0)
    end
end)

tool.Deactivated:Connect(function()
    if charging then
        charging = false
        
        chargeTrack:Stop()
        smashTrack:Play()
    end
end)

Is there any other more efficient way of doing this? Please help, thanks much.

Here’s what I mean by “charge”. I want it so that it will charge when Activated and would only strike when Deactivated. Thanks.

You could use AnimationEvents to indicate whenever the tool is fully charged instead of using a wait(). AnimationEvents can be used as a “Tick” to indicate the how charged is the weapon. When the animation reaches a “Tick”, you can make a value on the strength of the charge. The final AnimationEvent, you can adjust the speed of the animation to 0.

2 Likes