I just need help because whenever I try creating a cooldown, you can still spam the invisibility power.
01 | game.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() |
Using debounce
would be a good idea when making cooldowns:
01 | local debounce = false |
02 |
03 | game.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" ) |
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.