I'm not completely sure this is a Raycasting issue but I'm pretty new to it, so I'm trying to make a gun but im trying to get the basics of all the components before I put them all together, so I made a simple 2 part gun just for testing and it all works fine because right now I just want it so when you click, it goes from the gun to the mouse position, That works a little fine, it goes but not all the way, but also the bullet goes in both directions and not just the one way I want it to go.
Gun.Equipped:Connect(function(mouse)
mouse.Button1Down:Connect(function()
Shooting = true
print("Gun started shooting")
while Shooting == true do
wait(.01)
if Shooting == true then
local newRay = Ray.new(script.Parent.Barral.CFrame.p, (mouse.Hit.p - script.Parent.Barral.CFrame.p))
local part,position = game.Workspace:FindPartOnRay(newRay,game.Players.LocalPlayer.Character,false,true)
local Part = Instance.new("Part")
Part.Parent = game.Workspace
Part.CanCollide = false
Part.Anchored = true
Part.Parent = game.Workspace.Welds
Part.Anchored = true
Part.CanCollide = false
local distance = (script.Parent.Barral.CFrame.p - position).magnitude
Part.Size = Vector3.new(.3,.3, distance)
Part.CFrame = CFrame.new(script.Parent.Barral.CFrame.p, position) * CFrame.Angles(0,0, -distance/2)
script.Parent.RemoteFunction:InvokeServer()
else
end
end
end)
mouse.Button1Up:Connect(function()
Shooting = false
print("Gun stopped shooting")
end)
end)
There's my script, again pretty new to Raycasting so any help would be great, thank you!

8 comments
Now the size is becoming a little bigger than 2 studs.
Sorry wait didn't see the thing you added.
It goes in both directions again, and without the 70 or whatever range, it goes like 2 studs.
Change the CFrame.Angles to CFrame.new and see if it changes anything
Yes! Thank you! I have one more question though, what does .Unit do? I've been trying to find out what it does but I've had no luck.
It returns the direction its facing
its as in what your trying to get the direction of
Oh alright, thank you!