#How do I add a cooldown to the use of my tool?

30 messages · Page 1 of 1 (latest)

opal forum
#

I have a dumbell and an animation for it. I tried to add an animation but the cooldowns dont work. Does anyone know why?

also how do I make the code go into that fancy lua box?

**local Dumbell = script.Parent
local animation =script.Animation
animation.AnimationId = "rbxassetid://18551812338"
local Cooldown = false

Dumbell.Activated:Connect(function()

if Cooldown == false then

Cooldown = true

end

local humanoid = Dumbell.Parent:FindFirstChild("Humanoid")


humanoid.Animator:LoadAnimation(animation):Play()

wait(1)

if Cooldown == true then 
    wait(2)
    Cooldown = false
end

end

)**

dense estuary
#

im not that good at scripting. but my guess would be to replace cooldown with debounce

jaunty torrent
#

how long do u want ur cooldown to be?

onyx scaffoldBOT
#

studio** You are now Level 1! **studio

jaunty torrent
#

try dis: local Cooldown = false

Dumbell.Activatedblahblah

if Cooldown = true then
wait(2)

local Humanoid = Dumbell.Parent:FindFirstChild("Humanoid")

humanoid.Animator:LoadAnimation(animation):Play()

Cooldown = true

#

im new to scripting

#

so if that does not work pls dont be mad

opal forum
#

alr ill give it a try

#

aw man

#

this is wierd

jaunty torrent
#

what?

opal forum
#

still no cooldown

dense estuary
#

is there a error in output

opal forum
#

no

jaunty torrent
#

hmm

opal forum
dense estuary
#

have u tried the debounce thing?

jaunty torrent
#

try this: local Dumbell = script.Parent
local Animation = script.Animation
local Cooldown = false

local CooldownTime = 2 -- Adjust the cooldown time in seconds as needed

Dumbell.Activated:Connect(function()
if not Cooldown then
Cooldown = true

    -- Perform the action (play animation, etc.)
    local Humanoid = Dumbell.Parent:FindFirstChild("Humanoid")
    if Humanoid then
        local Animator = Humanoid:WaitForChild("Animator")
        local AnimationInstance = Animator:LoadAnimation(Animation)
        AnimationInstance:Play()
    end

    -- Start cooldown timer
    wait(CooldownTime)
    Cooldown = false
else
    -- Optionally provide feedback that action is on cooldown
    print("Action is on cooldown")
end

end)

opal forum
jaunty torrent
#

try my script

opal forum
#

ok

#

YOOO

opal forum
jaunty torrent
#

worked?

opal forum
#

yupp

jaunty torrent
#

thanks

#

have a goody day

opal forum
#

thanks guys

jaunty torrent
#

good*

#

you can adjust the cooldown time by adjusting local CooldownTime = 2 to ur liking