Ad
Log in to vote
1

cHow to shoot multiple projectiles??

Asked by 11 months ago
Edited 11 months ago

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?

0
Show script? more description? what are you actually trying to do? We can't help you if you 1) do not include code and 2) do not describe enough abnotaddable 862 — 11mo
0
omigosh stop using deprecated stuff it doesn't even work hiimgoodpack 1835 — 11mo
0
PLS USE CONTEXTACTIONSERVICE OR USERINPUTSERVICE abnotaddable 862 — 11mo
0
It does work NekoArtz 5 — 11mo

1 answer

Log in to vote
0
Answered by 11 months ago

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.

Ad

Answer this question