I'm trying to make a hammer that has a charging system. I don't want players to just spam click because that will beat the purpose of the charging system? How do I go about it?
This is what I've tried and it's horrible. Please help, thanks!
local tool = script.Parent
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local rootPart = character:WaitForChild("HumanoidRootPart")
local charge = script.Charge
local smash = script.Smash
local chargeTrack = humanoid:LoadAnimation(charge)
local smashTrack = humanoid:LoadAnimation(smash)
local charged = false
local cooldown = false
if not cooldown then
cooldown = true
tool.Activated:Connect(function()
if not charged then
smashTrack:Stop()
chargeTrack:Play()
delay(chargeTrack.Length - 0.02999, function()
chargeTrack:AdjustSpeed(0)
end)
charged = true
end
end)
tool.Deactivated:Connect(function()
if charged then
chargeTrack:Stop()
smashTrack:Play()
delay(smashTrack.Length - 0.02999, function()
smashTrack:AdjustSpeed(0)
rootPart.Anchored = true
wait(2)
smashTrack:Stop()
rootPart.Anchored = false
end)
charged = false
end
end)
wait(2)
cooldown = false
end

2 comments
Mind elaborating? Tried and it didn't really make things any better.
This script is confusing me bc I don't know what action is happening