How to make these bullets have spread?

So my gun system is one of those old RRP2 FE ones. I want to make a burst gun, so I duplicated the line of code that creates a bullet. It creates 3 bullets, but I don’t know how to make the bullet parts spread out. They just stay in a bunched up state and only 1 of them hit a target and damage. I’m also really bad at scripting, so I can’t figure this out.

Code:

	if hitObject then
					bullet = CreateBullet(bulletPos)
					bullet = CreateBullet(bulletPos)
					bullet = CreateBullet(bulletPos)

edit: I also saw this line that said cFrame, I’m not sure if that’s related to the bullet spread or not so I
l’ll just add it

local function CreateBullet(bulletPos)
	wait(0.04)
	local bullet = Instance.new('Part', Workspace)
	bullet.FormFactor = Enum.FormFactor.Custom
	bullet.Size = Vector3.new(0.1, 0.1, 0.1)
	bullet.BrickColor = BrickColor.new("Black")
	bullet.Shape = Enum.PartType.Block
	bullet.CanCollide = false
	bullet.CFrame = CFrame.new(bulletPos)
	bullet.Anchored = true
	bullet.TopSurface = Enum.SurfaceType.Smooth
	bullet.BottomSurface = Enum.SurfaceType.Smooth
	bullet.Name = 'Bullet'
	DebrisService:AddItem(bullet, 3)
	return bullet
end
2 Likes

You’ll need to provide a new angles cframe to the bullet Pos position which should look something like this: bulletPos = <BULLET_POS_HERE> * CFrame.Angles(math.radians(math.random(0,3)), math.radians(math.random(0,3)), math.radians(math.random(0,3))) . You’ll have to do this for each separate bullet, as otherwise they’ll all fire in the same random direction.

1 Like

like I said, I don’t really know how to script so what should i do for the <BULLET_POS_HERE>

bulletPos = 0.5 * CFrame.Angles(math.radians(math.random(0,3)), math.radians(math.random(0,3)), math.radians(math.random(0,3)))

I have no clue what I’m doing, something like this?

You already defined bulletPos, you’re literally passing it through to CreateBullet. All you have to do is edit that line and add the code I posted.

1 Like

sorry, I don’t really get how and what I’m supposed to edit?

Just change the bullet.CFrame line to this:
bullet.CFrame = CFrame.new(bulletPos) * CFrame.Angles(math.radians(math.random(0,3)), math.radians(math.random(0,3)), math.radians(math.random(0,3)))


sorry I’m just guessing at this point

You literally posted the CreateBullet function because you saw it said CFrame, I even said “change” ??? It isn’t rocket science.

I got the above error, and I fixed it by adding an extra “)” at the end of the line, but that still broke the gun.

I think you mean this.
(This goes before the 3 bullet variables)

Also make sure in the CreateBullet function that the cframe is just bulletPos, not CFrame.new(bulletPos)

bulletPos = CFrame.new(bulletPos) * CFrame.Angles(math.rad(math.random(0,3)), math.rad(math.random(0,3)), math.rad(math.random(0,3)))

it works, but the bullets are still in the same position. That little black dot is the bullet(s)

Even then, it’s best to just use a module like FastCast. No need to create individual bullets when a module that has realistic bullet physics can already do the same. There are already example models, so knock yourself out if you plan to use FastCast. It’s easy to use, and you can easily implement spread with it.

I’m fine with the gun system I’ve got right now, it’s just that making it shoot more than 1 bullet is a huge pain. I just want to fix the problem of the bullets not spreading, not my whole gun system

Well, I suppose just copy the bullet.cframe line in each create.
Ex:

bullet = CreateBullet(bulletPos)
bullet.CFrame = cf
bullet = CreateBullet(bulletPos)
bullet.CFrame = cf
bullet = CreateBullet(bulletPos)
bullet.CFrame = cf

Fun fact, you can turn it into a for loop.

for i = 1, 3 do
bullet = CreateBullet(bulletPos)
bullet.CFrame = cf
end

1 is the starting number, and 3 is the ending number

is cf “CFrame”? and is the placement behind the three bullet = CreateBullet(bulletPos)?

Yea, it’s CFrame.new(bulletPos) * the angle thing.

am I supposed to add a local cf = <somethingxd>

No, you replace cf with CFrame.new(bulletPos) * CFrame.Angles(math.rad(math.random(0,3)), math.rad(math.random(0,3)), math.rad(math.random(0,3)))

Sorry for not being specific.

like this?

					bullet.CFrame = CFrame.new(bulletPos) * CFrame.Angles(math.rad(math.random(0,3)), math.rad(math.random(0,3)), math.rad(math.random(0,3)))
					bullet.CFrame = CFrame.new(bulletPos) * CFrame.Angles(math.rad(math.random(0,3)), math.rad(math.random(0,3)), math.rad(math.random(0,3)))
					
					bullet = CreateBullet(bulletPos)
					bullet = CreateBullet(bulletPos)
					bullet = CreateBullet(bulletPos)