Why is my debounce not working properly?
This script creates a fireball and launches it from your hand. It works great, but I'm having a problem with the debounce. If I press Q once and launch one fireball, the debounce waits three seconds like it should, but if I press Q multiple times, a bunch of fireballs will launch, and then wait. What am I doing wrong?
001 | local Player = game.Players.LocalPlayer |
002 | local Mouse = Player:GetMouse() |
005 | local UIS = game:GetService( "UserInputService" ) |
007 | UIS.InputBegan:connect( function (Key, GPE) |
008 | if Key.KeyCode = = Enum.KeyCode.Q and not GPE then |
009 | if Debounce = = true then |
011 | local Animation = Player.Character.Humanoid:LoadAnimation(script.Animation) |
014 | local Part = Instance.new( "Part" , game.Workspace) |
015 | Part.CFrame = Player.Character [ "Right Arm" ] .CFrame * CFrame.new( 0 , 0 , - 2 ) |
017 | Part.Transparency = 1 |
018 | Part.CanCollide = false |
019 | Part.Size = Vector 3. new( 0.8 , 0.8 , 0.2 ) |
021 | Player.Character.Humanoid.WalkSpeed = 0 |
023 | local Decal = Instance.new( "Decal" , Part) |
025 | local Decal 2 = Instance.new( "Decal" , Part) |
030 | Part.Size = Part.Size + Vector 3. new( 0.5 , 0.5 , 0 ) |
034 | local FireBall = Instance.new( "Part" , game.Workspace) |
035 | FireBall.CFrame = Part.CFrame * CFrame.new( 0 , 0 ,- 3 ) |
036 | FireBall.Transparency = 1 |
037 | FireBall.Size = Vector 3. new( 1.2 , 2.4 , 0.8 ) |
039 | local Sound = Instance.new( "Sound" , FireBall) |
043 | local Fire = script.ParticleEmitter:Clone() |
044 | Fire.Parent = FireBall |
046 | local BodyVelocity = Instance.new( "BodyVelocity" ) |
047 | BodyVelocity.MaxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
048 | BodyVelocity.Velocity = Mouse.Hit.lookVector * 80 |
049 | BodyVelocity.Parent = FireBall |
051 | FireBall.Touched:Connect( function (hit) |
052 | local Humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
054 | Humanoid:TakeDamage( 40 ) |
057 | hit.CanCollide = = true then |
058 | local Smoke = script.EvilCloud:Clone() |
059 | Smoke.Parent = game.Workspace |
060 | Smoke.Anchored = true |
061 | Smoke.CFrame = hit.CFrame |
062 | Smoke.CanCollide = false |
064 | local Sound 3 = Instance.new( "Sound" , hit) |
068 | for i, v in pairs (hit.Parent:GetChildren()) do |
070 | local FindFire = v:FindFirstChild( "Fire" ) |
072 | local GiveFire = Instance.new( "Fire" , v) |
073 | GiveFire.Name = "GiveFire" |
082 | Smoke.Mesh.Scale = Smoke.Mesh.Scale + Vector 3. new( 0.5 , 0.5 , 0.5 ) |
089 | for x, y in pairs (hit.Parent:GetChildren()) do |
090 | local DeleteFire = y:FindFirstChild( "GiveFire" ) |
104 | Part.Size = Part.Size - Vector 3. new( 0.5 , 0.5 , 0.5 ) |
109 | Player.Character.Humanoid.WalkSpeed = 16 |