2 questions So i'm working on a machine gun but i want to to shoot out multiple bullets at once and or have a spraying effect that shoots out 1 bullet but the CFrame positions are random. Heres my script

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Ammo = 1
--CUSTOMIZE--
Mouse.Button1Down:connect(function()
		if Ammo > 0 then
			local x = Instance.new("Part", workspace)
			Ammo = Ammo-1
			x.Shape = "Block"
			x.CanCollide = false
			x.Size = Vector3.new(0.5, 0.5, 1.5)
			x.BrickColor = BrickColor.new("Bright yellow")
			x.TopSurface = "Smooth"
			x.BottomSurface = "Smooth"
			x.CFrame = Player.Character.Torso.CFrame * CFrame.new(0,0,-3)
				
			
--DAMAGE--		
			x.Touched:connect(function(hit)
				if hit.Parent:FindFirstChild("Humanoid") ~= nil then
					hit.Parent.Humanoid:TakeDamage(12.5)
			x:remove()
				end
			end)
--VELOCITY--
local 		v = Instance.new("BodyVelocity", x)
			v.Velocity = Player.Character.Torso.CFrame.lookVector * 150
			
			v.maxForce = Vector3.new(math.huge, math.huge, math.huge)			
			
			x.Parent = workspace
			wait(1.25)
			
			x:remove()
			
		end
end)
--AMMO--
while true do
	if Ammo == 0 then
		wait(0.1)
		Ammo = 1
		end
		wait(0.1)
end

For my first question about shooting multiple parts at once, i duplicated the script and it works but im wondering if theres a less messy way of doing it without having so many scripts

And for my 2nd question about the spraying, i tried using or but that doesn't work

6 comments

0

The parent argument to instance.new is deprecated, assign in another line.

0

connect, maxForce, :remove are all deprecated.

0

the script still works, deprecated or not

0

If you're just looking to have it shoot multiple times at once, throw a loop in your event that's wrapped by either a Spawn() or a coroutine; either should allow your code to work concurrently. i.e. Mouse.Button1Down:Connect(function() Spawn(function() for i, numberOfBulletsToFire do --fire bullet end end) end);

0

As a note though, I would recommend fixing both the deprecated parameter in Instance.new and :remove (use :Destroy instead), simply because those are actually deprecated with good reason. Both will help the performance of your game. Changing connect to Connect and maxForce to MaxForce is purely convention, I recommend using them properly in new code, but it's not a huge problem if you leave them a

0

It's always good practice to deviate from deprecated code, even if it's not the problem. Deprecated code can be removed completely at any time.