Raycast Gun Spread is Stronger The Closer ray is

I made a spread system for my gun, but the problem is that the closer you are to the target, the more spread it is.

Script:```

		local ray = Ray.new(FirePos.Position,(mouse.Hit.p-FirePos.Position + Vector3.new(math.random(-Spread,Spread),math.random(-Spread,Spread),math.random(-Spread,Spread))).unit*Range)

Video:

This is not the full script. The other parts are not necessary to my problem.

2 Likes

Unrelated, but Please do not use Ray.new() and workspace:FindPartOnRay() as those have been Deprecated due to the new Raycast system, Instead use RaycastParams and workspace:Raycast()

4 Likes

i tried making it work:raycast but i don’t know what to do on pos line, i tried a lot of things but they didn’t work

	local ray = workspace:Raycast(FirePos.Position,(mouse.Hit.p-FirePos.Position--[[ + Vector3.new(math.random(-Spread,Spread),math.random(-Spread,Spread),math.random(-Spread,Spread))]]).unit*Range)
			local hit = nil
			local pos = 
1 Like

Raycast will return a set of Values, which you can look at here

In Short, just type ray.Position and ray.Instance.

3 Likes

i tried but it errored on
image
i put code to

local ray = workspace:Raycast(FirePos.Position,(mouse.Hit.p-FirePos.Position--[[ + Vector3.new(math.random(-Spread,Spread),math.random(-Spread,Spread),math.random(-Spread,Spread))]]).unit*Range)
			local hit,pos = ray.Position,ray.Instance
2 Likes
local ray = workspace:Raycast(FirePos.Position,(mouse.Hit.p-FirePos.Position + Vector3.new(math.random(-Spread,Spread),math.random(-Spread,Spread),math.random(-Spread,Spread))).unit*Range).Unit * whateverRangeYouWant

This might work

1 Like

i tried and it says error
image