So, hello, I’m currently making a shotgun(Used my old model which was a laser gun), I don’t know how to add a spread in it, and I’m of course, bad at maths, but I put a for loop in it, I know this type of question was already asked, but I don’t understand those. Here’s my code:
local BeamEvent = script.Parent:WaitForChild("Beam")
local debris = game:GetService("Debris")
BeamEvent.OnServerEvent:Connect(function(Player, laserpos, target)
local ray = Ray.new(laserpos, (target - laserpos).Unit*550)
local hit, position = game.Workspace:FindPartOnRay(ray, nil)
pcall(function()
for i = 1, 4 do
local HumanoidToDamage = hit.Parent:FindFirstChild("Humanoid")
if HumanoidToDamage and HumanoidToDamage ~= Player.Character.Humanoid then
HumanoidToDamage:TakeDamage(99)
print(HumanoidToDamage.Parent.Name .. " just got hit by beam. ")
end
local Beam = Instance.new("Part", game.Workspace)
Beam.Name = "Beam"
Beam:SetNetworkOwner(nil)
local dist = (target - laserpos).magnitude
Beam.Size = Vector3.new(0.3,0.3, dist)
Beam.CFrame = CFrame.new(laserpos,position) * CFrame.new(0,0,-dist/2)
Beam.Anchored = true
Beam.CanCollide = false
Beam.BrickColor = BrickColor.new("Really red")
Beam.Material = Enum.Material.Neon
debris:AddItem(Beam, .1)
print("Beam Destroyed")
end
end)
end)
Help is very, very, very appreciated