I'm creating a custom gun system but the issue I've ran into is whenever I go to shoot at a certain angle the bullet always travels in the same direction..
issue is on lines 65-69
wait()
--services
local lighting = game:GetService("Lighting")
local serverstorage = game:GetService("ServerStorage")
local workspace = game:GetService("Workspace")
-- variables
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character
local torso = script.Parent.Torso
local gun = lighting.Models:FindFirstChild("AR15")
local gun2
local main
local cam = game.Workspace.CurrentCamera
local sprint = false
local walk = false
-- functions
local function weldBetween(a, b)
--Make a new Weld and Parent it to a.
local weld = Instance.new("ManualWeld", a)
weld.Part0 = a
weld.Part1 = b
--Get the CFrame of b relative to a.
weld.C0 = a.CFrame:inverse() * b.CFrame
--Return the reference to the weld so that you can change it later.
return weld
end
function wepCreate()
local a = gun:Clone()
a.Main.CanCollide = false
local b = gun:FindFirstChild("Main")
a.Parent = character
b.CFrame = CFrame.new(torso.Position + Vector3.new(-0.5, 0, -3))
weldBetween(gun.Main, torso)
gun2 = a
main = gun2:FindFirstChild("Main")
end
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.R then
wepCreate()
wait()
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)
mouse.Button1Down:connect(function()
print("Mouse pressed!")
local ray = Ray.new(main.CFrame.p, (mouse.Hit.p - main.CFrame.p).unit * 300)
local part, position = workspace:FindPartOnRay(ray, player.Character, false, true)
local beam = Instance.new("Part", workspace)
beam.BrickColor = BrickColor.new("Black")
beam.FormFactor = "Custom"
beam.Material = "Plastic"
beam.Shape = "Ball"
beam.TopSurface = "Smooth"
beam.BottomSurface = "Smooth"
beam.Anchored = false
beam.Locked = true
beam.CanCollide = false
local distance = 50
beam.Size = Vector3.new(1, 1, 1)
local d = Instance.new("BodyVelocity", beam)
d.Velocity = Vector3.new(main.lookVector)
beam.CFrame = CFrame.new(main.Position + Vector3.new(0,0, -5))
game:GetService("Debris"):AddItem(beam, 3)
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(30)
end
end
end)

3 comments
the raycasting part is apart of the older system I'm trying it with a different method kept the raycast thingy in there just in case I decided to not use a part
also how do I make the bullets come out of the end of the part called main in the AR15 model?
bullet.CFrame = AR15.CFrame.p