wait(1) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local humanoid = player.Character.Humanoid local s = humanoid:LoadAnimation(game.StarterPack.StarterPack.Animation) Player = script.Parent.Parent -- Gets LocalPlayer Character = Player.Character -- Gets Players Character Mouse = Player:GetMouse() function onKeyDown(key) key = key:lower() if key == "f" then s:Play() player.Character.Humanoid.WalkSpeed = 16 wait(.73) local x = Instance.new("Part") x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Shape = "Ball" x.Transparency = .7 x.BrickColor = BrickColor.new("Bright red") x.Size = Vector3.new(10, 10, 10) local z = Instance.new("Fire") z.Parent = x z.Size = 12 z.Heat = 12 local explosion = Instance.new("Explosion") explosion.Parent = game.Workspace explosion.Position = x.Position local y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.velocity = Character.Torso.CFrame.lookVector*80 y.Parent = x x.Parent = game.Workspace x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12) wait(3.5) x:remove() end end Mouse.KeyDown:connect(onKeyDown)
This is a fireball script, I hate that I could just spam F and a million fireballs are out. How do I stop this from being spammed?
And how would i make this fireball do damage?
Add in a debounce.
wait(1) local player = game.Players.LocalPlayer local Mouse = player:GetMouse() local humanoid = player.Character.Humanoid local s = humanoid:LoadAnimation(game.StarterPack.StarterPack.Animation) Player = script.Parent.Parent -- Gets LocalPlayer Character = Player.Character -- Gets Players Character Mouse = Player:GetMouse() usable = true function onKeyDown(key) key = key:lower() if key == "f" and usable then -- Check if the skill can be used usable = false -- Make the skill unusable s:Play() player.Character.Humanoid.WalkSpeed = 16 wait(.73) local x = Instance.new("Part") x.TopSurface = "Smooth" x.BottomSurface = "Smooth" x.Shape = "Ball" x.Transparency = .7 x.BrickColor = BrickColor.new("Bright red") x.Size = Vector3.new(10, 10, 10) local z = Instance.new("Fire") z.Parent = x z.Size = 12 z.Heat = 12 local explosion = Instance.new("Explosion") explosion.Parent = game.Workspace explosion.Position = x.Position local y = Instance.new("BodyVelocity") y.maxForce = Vector3.new(math.huge, math.huge, math.huge) y.velocity = Character.Torso.CFrame.lookVector*80 y.Parent = x x.Parent = game.Workspace x.CFrame = Character.Torso.CFrame*CFrame.new(0, 0, -12) wait(3.5) x:remove() wait(5) -- Or however long you want the cooldown to be. usable = true -- Make the skill usable again. end end Mouse.KeyDown:connect(onKeyDown)
EDIT: Helpful links, as requested...
Tutorials: Don't just read this. Become this. (Kidding, it isn't that important) But, for real, read through this. These tutorials can not only help you to do specific things, if you follow through them, test as you go, and do each tutorial from beginner to advanced, you'll start to grasp Lua super quick. When I got into Lua a couple of months ago I actually downloaded the webpage for offline viewing and looked over it in my spare time (as I did with the next one), and it really helped me.
The Holy Bible: Or, the Scripting Book. This one is a lot less goal-oriented, and instead shows you what different things are step by step. Useful for learning terminology and syntax, and how to do some of the more advanced stuff.
Literally all of the Wiki: This just contains some info about certain stuff, and if you click that big button under "Absolute beginner's guide to scripting", it will bring you to the absolute beginner's guide to scripting. Who woulda thought?
Scripting Helpers: Great site. 10/10. Would recommend. Try looking through the questions (old and new) on this site. Reading problems that other people had can help you avoid them in the future, and can help you have a better grasp on Lua in general. Of course, if a script isn't working, you can always ask for help as well!
This is a tip and not a link, but it's going here anyway: Know your scripts. I've seen the one you're using before many times, and I figure it's safe to assume that you're fairly new to scripting, as you didn't know what a variable is. Don't just copy and paste because the internet said that it does a specific thing. Take the time to look over scripts, and if you're doing a tutorial off of, say, YouTube, make sure you actually know what everything is doing. This will help you to understand the different aspects of RBXLua, and will help you to reproduce things in your own way.
Oh, P.S., I personally prefer the newer input method. The one you're using is deprecated.