How to make shotgun accuracy decrease in distance?

I am making a gun using raycasting, and i want to be able to make shotguns work like they do in other games. I already tried to write code to do this, but it spreads the same reguardless of distance. What should I do?
My spread code that i use for the shotgun:

local function doSpread(bool)
	local spread = gunSettings.Spread
	local random =
	if bool or gunSettings.SpreadEnabled then
		return mouse.Hit*,spread),random:NextNumber(-spread,spread),0)
		return mouse.Hit
1 Like

Multiply the spread by the shotgun’s distance, divided by a number (to prevent spread from getting out of control).