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

How can i add a cool down to this key bind magic script?

Asked by 4 years ago
Edited 4 years ago
01Player = game.Players.LocalPlayer
02repeat wait() until Player.Character
03c = Player.Character
04mouse = Player:GetMouse()
05 
06mouse.TargetFilter = workspace.AntiMouse
07UIS = game:GetService("UserInputService")
08 
09UIS.InputBegan:connect(function(input, isTyping)
10    if isTyping then return end
11    if input.KeyCode == Enum.KeyCode.Q then
12        script.Function:FireServer("Projectile", c.HumanoidRootPart.CFrame, mouse.hit.p)
13        local debounce = false
14    end
15end)

I need help adding a cooldown to this because its spammable, and the character can spam magic projectiles which is what i dont want.The first script is for the key bind and the second script is for the projectile and when it hits a object or character an explosion would happen. Can someone help me with a cooldown and where would i put it? At the end? I've tried looking into debounce but it wont work. I hope someone can help me, thanks.

01script.Parent.OnServerEvent:connect(function(Player, Action, V1, V2)
02    local c = Player.Character
03    if Action == "Projectile" then
04        local P = Instance.new("Part")
05        P.Name = Player.Name.."Projectile"
06        P.Transparency = 1
07        P.Size = Vector3.new(2,2,2)
08        P.CFrame = V1*CFrame.new(0,0,-2)
09        P.CFrame = CFrame.new(P.Position, V2)
10        P.Parent = workspace.AntiMouse.Projectiles
11        P.CanCollide = false
12        game.Debris:AddItem(P,10)
13        local PFX = script.ProjectileFX:clone()
14        PFX.Parent = P
15        PFX.Enabled = true
View all 49 lines...

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Check it with a variable

01Player = game.Players.LocalPlayer
02repeat wait() until Player.Character
03c = Player.Character
04mouse = Player:GetMouse()
05 
06mouse.TargetFilter = workspace.AntiMouse
07UIS = game:GetService("UserInputService")
08Cooldown = false --Setting up a variable for cooldown.
09 
10UIS.InputBegan:connect(function(input, isTyping)
11    if isTyping then return end
12    if input.KeyCode == Enum.KeyCode.Q then
13    if Cooldown == false then --Checking if there is no cooldown active.
14    Cooldown = true --Setting it up so the cooldown is active
15         script.Function:FireServer("Projectile", c.HumanoidRootPart.CFrame, mouse.hit.p)
16    wait(2) --Waiting until setting cooldown to false change 2 to how ever many seconds.
17    Cooldown = false --Setting Cooldown to false so user can use spell again.
18        end
19    end
20end)
0
Where would i put this? Funnyskyswagway3 30 — 4y
0
replace script #1 with it Gooncreeper 98 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

Change the wait time.

Answer this question