So all I did was take the raycasting from the wiki and edit it a bit, and tried to make it into a shotgun, I can but having a little trouble with what the title states.
local Tool = script.Parent
local player = game:GetService("Players").LocalPlayer
local vExit = Tool:WaitForChild("Exit")
Tool.Equipped:connect(function(mouse)
mouse.Button1Down:connect(function()
local ray = Ray.new(Tool.Exit.CFrame.p, (mouse.Hit.p - Tool.Exit.CFrame.p).unit * 45)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
for i = 1, 10 do --makes more than one part/beam brick
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Medium stone grey")
beam.FormFactor = "Custom"
beam.Material = "Plastic"
beam.Transparency = 0.825
beam.Anchored = true
beam.Locked = true
beam.CanCollide = false
local distance = (Tool.Exit.CFrame.p - position).magnitude
beam.Size = Vector3.new(0.05, 0.05, distance)
beam.CFrame = CFrame.new(Tool.Exit.CFrame.p, position) * CFrame.new(0,0--[[ This is where I'm having trouble I can use math.random to replace the 0's but the bullets come out of nowhere, offset to the side, how can I fix that?]], -distance / 2)
game:GetService("Debris"):AddItem(beam, 0.1)
if part then
local humanoid = part.Parent:FindFirstChild("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
end
if humanoid then
humanoid:TakeDamage(math.random(3.5,7))
end
end
end
end)
end)

3 comments
thats what i was thinking, but i couldnt put it into words
Thanks for the help, apparently line 10 needed to be "local ray = Ray.new(Tool.Exit.Position," because I placed it at the end of the barrel.
No problem.