Shotgun.OnServerEvent:Connect(function(Player,TargetPos,Handle,FirePart, gunType)
if gunType == "Shotgun" then
Handle.ShotSound:Play()
for i = 1,BulletsPerShot do
local Dir = CFrame.new(FirePart.Position, TargetPos)*CFrame.Angles(math.rad(math.random(-ShotgunSpread,ShotgunSpread)),math.rad(math.random(-ShotgunSpread,ShotgunSpread)),0)
local RayCast = Ray.new(FirePart.Position - Dir.LookVector*Range)
local Target,Pos = game.Workspace:FindPartOnRay(RayCast,Player.Character,false,true)
if Target then
local Hum = Target.Parent:FindFirstChild("Humanoid")
if Hum then
Hum:TakeDamage(ShotgunDamage)
end
end
local Vis = Instance.new("Part",game.Workspace)
Vis.Anchored = true
Vis.CanCollide = false
Vis.Color = Color3.new(1,1,0)
local Dist = (Pos - FirePart.Position).magnitude
Vis.CFrame = Dir*CFrame.new(0,0,-Dist)
Vis.Size = Vector3.new(0.1,0.1,Dist*2)
game.Debris:AddItem(Vis,0.4)
end
end
end)
bc the target part where it finds the humanoid it doesn’t work.