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

Shoot out multiple parts at once?

I have this local script that shoots out a projectile when you click.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()
Ammo = 8

Mouse.Button1Down:Connect(function()
	if Ammo > 0 then
local	x = Instance.new("Part", workspace)
       	Ammo = Ammo -1
		x.Shape = "Block"
		x.Size = Vector3.new(0.5,0.5,1.5)
		x.CanCollide = false
		x.BrickColor = BrickColor.new("New Yeller")
		x.Material = "Neon"
		x.CFrame = Player.Character.Torso.CFrame * CFrame.new(0,0,-3)
		x.TopSurface = "Smooth"
		x.BottomSurface = "Smooth"
			
		x.Touched:Connect(function(hit)
			if hit.Parent:FindFirstChild("Part") then
				x:Destroy()
			end --Part Destroy
			
			if hit.Parent:FindFirstChild("Humanoid") ~= nil then
				hit.Parent.Humanoid:TakeDamage(25)
				x:Destroy()
			end --Humanoid Destory/Damage end
			
			
		end)--Touched end
		
local	v = Instance.new("BodyVelocity", x)
		v.Velocity = Player.Character.Torso.CFrame.lookVector * 500
		v.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		
		if Ammo == 0 then
			wait(2)
			Ammo = 8
		end --Reload end
		
		wait(1.5)
		x:Destroy()
		
	end -- Ammo>0 end
	
end)--Button1Down end

I want a way to shoot out multiple parts. I'm pretty sure just copying and pasting the same thing over and over would work but it gets too sloppy. I also duplicated the script and it works but i think it looks sloppy. I want an easier,simple,efficient, and clean way of doing it. Thanks!

1 comment

0

The parent argument to Instance.new is deprecated, I'd assign the parent as the last property in another line

1 answer

You can always wrap the code in a for statement and then repeat it the amount of times you want it to shoot.

Another approach would be to make a function for it and then call it multiple times.

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