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?
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() local Debounce = true local UIS = game:GetService("UserInputService") UIS.InputBegan:connect(function(Key, GPE) if Key.KeyCode == Enum.KeyCode.Q and not GPE then if Debounce == true then local Animation = Player.Character.Humanoid:LoadAnimation(script.Animation) Animation:Play() local Part = Instance.new("Part", game.Workspace) Part.CFrame = Player.Character["Right Arm"].CFrame * CFrame.new(0, 0, -2) Part.Anchored = true Part.Transparency = 1 Part.CanCollide = false Part.Size = Vector3.new(0.8, 0.8, 0.2) Player.Character.Humanoid.WalkSpeed = 0 local Decal = Instance.new("Decal", Part) Decal.Texture = "rbxassetid://301362847" local Decal2 = Instance.new("Decal", Part) Decal2.Texture = "rbxassetid://301362847" Decal2.Face = "Back" for i = 1, 11 do Part.Size = Part.Size + Vector3.new(0.5,0.5,0) wait() end local FireBall = Instance.new("Part", game.Workspace) FireBall.CFrame = Part.CFrame * CFrame.new(0,0,-3) FireBall.Transparency = 1 FireBall.Size = Vector3.new(1.2, 2.4, 0.8) local Sound = Instance.new("Sound", FireBall) Sound.SoundId = "rbxassetid://182382770" Sound:Play() local Fire = script.ParticleEmitter:Clone() Fire.Parent = FireBall local BodyVelocity = Instance.new("BodyVelocity") BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge) BodyVelocity.Velocity = Mouse.Hit.lookVector * 80 BodyVelocity.Parent = FireBall FireBall.Touched:Connect(function(hit) local Humanoid = hit.Parent:FindFirstChild("Humanoid") if Humanoid then Humanoid:TakeDamage(40) FireBall:Destroy() elseif hit.CanCollide == true then local Smoke = script.EvilCloud:Clone() Smoke.Parent = game.Workspace Smoke.Anchored = true Smoke.CFrame = hit.CFrame Smoke.CanCollide = false local Sound3 = Instance.new("Sound", hit) Sound3.SoundId = "rbxassetid://304529688" Sound3:Play() for i, v in pairs(hit.Parent:GetChildren()) do print(v) local FindFire = v:FindFirstChild("Fire") if not FindFire then local GiveFire = Instance.new("Fire", v) GiveFire.Name = "GiveFire" end end FireBall:Destroy() for y = 1, 40 do Smoke.Mesh.Scale = Smoke.Mesh.Scale + Vector3.new(0.5,0.5,0.5) wait() end wait(1) Smoke:Destroy() wait(2) for x, y in pairs(hit.Parent:GetChildren()) do local DeleteFire = y:FindFirstChild("GiveFire") if DeleteFire then DeleteFire:Destroy() end end end end) wait(0.70) for x = 1, 15 do Part.Size = Part.Size - Vector3.new(0.5,0.5,0.5) wait() end Part:Destroy() Player.Character.Humanoid.WalkSpeed = 16 Debounce = false wait(3) Debounce = true end end end)
I'm not sure if this is right but try putting
Debounce = false
in the beginning after
if Debounce == true then