Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

cHow to shoot multiple projectiles??

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?

4 comments

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

0

omigosh stop using deprecated stuff it doesn't even work

0

PLS USE CONTEXTACTIONSERVICE OR USERINPUTSERVICE

0

It does work

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.