So I have a script that is keydown to shoot one projectile but how do I make it shoot multiple projectiles when I press the key?
local Player = game.Players.LocalPlayer local Mouse = Player:GetMouse() Mouse.KeyDown:connect(function(Key) if Key == 'e' then local Part = game.ServerStorage.Fireball:Clone() Part.Parent = game.Workspace Part.CFrame = Player.Character.Torso.CFrame * CFrame.new(-.1,0,-5) local y = Instance.new("BodyVelocity") y.MaxForce = Vector3.new(math.huge,math.huge,math.huge) y.Velocity = Player.Character.Torso.CFrame.lookVector*160 y.Parent = Part script.Disabled = true wait(2) script.Disabled = false end end)
This is for one fireball but how do I make it fire multiple times if I press the key e?
Okay. Firstly, you should probably be using UserInputService. To make it this way, instead of using mouse as the connection, use this base.
local Player = game.Players.LocalPlayer local uis = game:GetService("UserInputService") uis.InputBegan:connect(function(input,processed) if input.UserInputType == Enum.UserInputType.Keyboard and not processed then if input.KeyCode == your key then -- code end end end)
However, to make it fire multiple times, just move the code into a function, like so.
function fire() -- firing code end
This'd go prior to the 'uis' function, which would be similar to this.
local Player = game.Players.LocalPlayer local uis = game:GetService("UserInputService") uis.InputBegan:connect(function(input,processed) if input.UserInputType == Enum.UserInputType.Keyboard and not processed then if input.KeyCode == your key then for i=1, number of times you want it to fire do fire() wait() end end end end)
The for loop repeats the code within it for the amount of times specified. If you need anything else, let me know.