Ad
Log in to vote
1

cHow to shoot multiple projectiles??

Asked by 2 months ago
Edited 2 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 712 — 2mo
0
omigosh stop using deprecated stuff it doesn't even work hiimgoodpack 1487 — 2mo
0
PLS USE CONTEXTACTIONSERVICE OR USERINPUTSERVICE abnotaddable 712 — 2mo
0
It does work NekoArtz 5 — 1mo

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by 2 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



Ad