Advertisement
Sungmingamerpro13

New ToolScript (Tool + Stacks)

Jan 4th, 2025
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 0.99 KB | None | 0 0
  1. local Tool = script.Parent
  2. local uses = 0
  3. local maxUses = 2
  4. local cooldown = 0-- Cooldown time in seconds
  5. local animationId = 15036314680
  6. local canUse = true  -- Flag to track if the tool can be used
  7.  
  8. -- Load the animation
  9. local animation = Instance.new("Animation")
  10. animation.AnimationId = "rbxassetid://" .. animationId
  11.  
  12. -- Connect the animation to the Humanoid
  13. local function playAnimation(humanoid)
  14.     local track = humanoid:LoadAnimation(animation)
  15.     track:Play()
  16. end
  17.  
  18. Tool.Activated:Connect(function()
  19.     if canUse and uses < maxUses then
  20.         local h = Tool.Parent:FindFirstChild("Humanoid")
  21.         if h then
  22.             canUse = false  -- Set the flag to prevent spamming
  23.             playAnimation(h)  -- Play the animation
  24.             h.Health = h.Health + 15
  25.             uses = uses + 1
  26.             wait(cooldown)  -- Wait for the cooldown period
  27.             canUse = true
  28.             -- Reset the flag
  29.             if uses == maxUses then
  30.                 Tool.stacks.Value -= 1
  31.                 if Tool.stacks.Value == 0 then
  32.                     Tool:Destroy()
  33.                 end
  34.             end
  35.         end
  36.     end
  37. end)
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement