Why is my spread like this!

Hello!
So im making a shotgun and make it spread. It seems to work fine until i found this problem:


Instead of the bullet getting out of the barrel. It came out of no where! I dont know whats the problem about this, heres the script:

		local maxspread = 10
		local spreaddivider = 1
		local spreaddistance = Vector3.new(math.random(-maxspread,maxspread)/spreaddivider,math.random(-maxspread,maxspread)/spreaddivider,math.random(-maxspread,maxspread)/spreaddivider)
		local direction = (((mousep + spreaddistance) - originpos).Unit) * distance
local midpoint = originpos+direction/2

It seems pretty normal, or is something wrong? Please help!

Just lower this down I guess?

math.random(-10, 10) = 4 / 1 = 4
You don’t really need the spreaddivider.

Oh wait im sorry, i messed up with the stuff this is new one:

local maxspread = 3
local spreaddivider = 70

Now, kinda see the problem. Lower the down the maxspread to 1.5 or 1.75 or something like that. And, change the spreaddivider around 65-80, and then maybe try?

EDIT:
This is what happens when I try 1.5 / 70
image

1.5 / 65
image

1.75 / 80
image

Approximately you get 0.021 as your result.

EDIT 2: Your spreaddivider will affect your spreading as I noticed. The higher it is, the lower it spreads.

EDIT 3: Your code is correct, it’s just the variables you need to mess with.

It does work but the problem is still continuing :frowning: the origin of the bullet didnt came out of the barrel :sob:

Pretty weird if you ask me. What other place of the code do you think is the reason for this? (Not in the code you provided, the full code you have right now.)

Nvm, it put a test script and forgot to put it out :rofl: :pensive:. Sorry about that

Ain’t no problem, we make mistakes! Good luck on your game!