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
local function Pew()
update_ammo()
FireEvent:FireServer(Mouse.Hit.p, tool.Handle, FirePart, “Shotgun”)
tool.Bullets.Value = tool.Bullets.Value - 1
end
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.