How can i add a cool down to this key bind magic script?
Asked by
4 years ago Edited 4 years ago
01 | Player = game.Players.LocalPlayer |
02 | repeat wait() until Player.Character |
04 | mouse = Player:GetMouse() |
06 | mouse.TargetFilter = workspace.AntiMouse |
07 | UIS = game:GetService( "UserInputService" ) |
09 | UIS.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 |
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.
01 | script.Parent.OnServerEvent:connect( function (Player, Action, V 1 , V 2 ) |
02 | local c = Player.Character |
03 | if Action = = "Projectile" then |
04 | local P = Instance.new( "Part" ) |
05 | P.Name = Player.Name.. "Projectile" |
07 | P.Size = Vector 3. new( 2 , 2 , 2 ) |
08 | P.CFrame = V 1 *CFrame.new( 0 , 0 ,- 2 ) |
09 | P.CFrame = CFrame.new(P.Position, V 2 ) |
10 | P.Parent = workspace.AntiMouse.Projectiles |
12 | game.Debris:AddItem(P, 10 ) |
13 | local PFX = script.ProjectileFX:clone() |
16 | local BV = Instance.new( "BodyVelocity" ) |
17 | BV.maxForce = Vector 3. new( 25000 , 25000 , 25000 ) |
18 | BV.Velocity = P.CFrame.lookVector* 25 |
21 | P.Touched:connect( function (Hit) |
22 | if Trigger = = false and Hit.Parent.ClassName ~ = "Accessory" and Hit.Parent ~ = c and Hit.Name ~ = Player.Name.. "Projectile" and Hit.Parent ~ = workspace.AntiMouse.FX then |
26 | game.Debris:AddItem(P, 1 ) |
28 | local FX = game.ServerStorage.FX.CustomMeshFX:clone() |
29 | FX.Color = Color 3. fromRGB( 255 , 255 , 255 ) |
31 | FX.Parent = workspace.AntiMouse.FX |
32 | game.Debris:AddItem(FX, 2 ) |
34 | local Reg = Region 3. new(P.Position-Vector 3. new( 6 , 6 , 6 ),P.Position+Vector 3. new( 6 , 6 , 6 )) |
35 | local RTable = workspace:FindPartsInRegion 3 (Reg, c) |
36 | for i,v in pairs (RTable) do |
37 | if v.Name = = "HumanoidRootPart" and v.Parent:findFirstChild( "Humanoid" ) and v.Parent:findFirstChild( "ProjectileDeb" ) = = nil then |
38 | local Deb = Instance.new( "BoolValue" ) |
39 | Deb.Name = "ProjectileDeb" |
40 | game.Debris:AddItem(Deb, 0.2 ) |
41 | v.Parent.Humanoid:TakeDamage( 5 ) |
42 | local debounce = false |