Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would i go about creating a cooldown for invisibility power?

Asked by 4 years ago

I just need help because whenever I try creating a cooldown, you can still spam the invisibility power.

01game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
02    if key == "e" then
03        local TS = game:GetService("TweenService")
04        local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
05        for _, v in pairs(script.Parent:GetDescendants()) do
06            if v:IsA("BasePart") and v.Name~= "HumanoidRootPart" then
07                TS:Create(v, Info, {Transparency=1}):Play()
08            end
09        end
10        wait(20)
11        local TS = game:GetService("TweenService")
12        local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
13        for _, v in pairs(script.Parent:GetDescendants()) do
14            if v:IsA("BasePart") and v.Name~= "HumanoidRootPart" then
15                TS:Create(v, Info, {Transparency=0}):Play()
View all 21 lines...

1 answer

Log in to vote
1
Answered by
7777ert 49
4 years ago

Using debounce would be a good idea when making cooldowns:

01local debounce = false
02 
03game.Players.LocalPlayer:GetMouse().KeyDown:Connect(function(key)
04    if key == "e" then
05        if not debounce then
06            debounce = true
07            local TS = game:GetService("TweenService")
08            local Info = TweenInfo.new(2, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
09            for _, v in pairs(script.Parent:GetDescendants()) do
10                if v:IsA("BasePart") and v.Name~= "HumanoidRootPart" then
11                    TS:Create(v, Info, {Transparency=1}):Play()
12                end
13            end
14            wait(20)
15            local TS = game:GetService("TweenService")
View all 26 lines...

In this script, a variable debounce was added (you can change the variable name if you want to). It was false at first. When you pressed E, it will check if debounce is false. If yes, if will turn debounce to true and run the tween. Then it will wait until it finished cooling down and turn it to false again.

Ad

Answer this question