How do I make a shotgun bullet spread with raycast?

    local Beam = Instance.new("Part", workspace)
Beam.BrickColor = BrickColor.new("White")
Beam.FormFactor = "Custom"
Beam.Transparency = 0.25
Beam.Material = "Neon"
Beam.Anchored = true
Beam.CanCollide = false

local Distance = (FirePart.Position - Target).magnitude
Beam.Size = Vector3.new(0.1,0.1,Distance)
Beam.CFrame = CFrame.new(FirePart.Position, Target)* CFrame.new(0,0, -Distance/2)

game.Debris:AddItem(Beam, 0.1)

local NewRay = RaycastParams.new()
local RayDirection = (Target - FirePart.Position) * Range

NewRay.FilterDescendantsInstances = {Player.Character}

local Result = workspace:Raycast(FirePart.Position, RayDirection, NewRay)

if Result then
	if Result.Instance then
		if Result.Instance.Parent:FindFirstChild("Humanoid") then
			Result.Instance.Parent.Humanoid.Health -= UziDamage
		end
	end
end

end

1 Like

You’re gonna need to provide more information than just the script.

1 Like

like what else would i need the provide? like the local script for the gun?

2 Likes

local function Pew()
update_ammo()
FireEvent:FireServer(Mouse.Hit.p, tool.Handle, FirePart, “Shotgun”)
tool.Bullets.Value = tool.Bullets.Value - 1
end

2 Likes

This probably isn’t the best way to do shotgun spread, but it’s the way that I do it, and I think it’s pretty easy to understand.

Pick a distance that is away from the initial firing position, say 10 studs.

Take the position of the firing direction at 10 studs, and offset it in the X and Y directions sort of like a 2d coordinate plane, but it’s being mapped infront of the weapon’s barrel.

You want to construct a new firing direction for the pellet of the shotgun based on the randomized offset by doing (offsetPosition - firingPosition).unit

You want to play around with the offset values and the distance where you map the coordinate plane at, but I’ve made it work pretty solid before.

1 Like

Do you mean move a bullet? If yes you could use TweenService to a really accurate movement.

No i mean like multiple bullets get fired from a shotgun and it makes a couple of lines.

1 Like

would that be in the Server Script or the one that is firing to the server script from the client?

1 Like

Here is a video that shows how to make a shotgun which has spread as what you are saying: Roblox NOT tutorial how to make a shotgun - YouTube

5 Likes

Ayee this is some nice sauce. Very helpful!

3 Likes