Making Gun script?

  1. What do you want to achieve?

I want to make a gun like Jailbreaks. Only I’m not using a tool for this right now I just use a basic Raycast and mouse

  1. What is the issue?

I’m not sure how to make the bullet shoot in the direction of the mouse.

  1. What solutions have you tried so far?

Searched up some raycasting tutorials. and looked at api’s

This is as far as I have got but it does not shoot in the direction of the mouse.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerGetMouse = LocalPlayer:GetMouse()

local PartVelocity = 1000
local Delay = 0

local Number = 1

local Folder = Instance.new("Folder")
Folder.Name = "Part's Folder"
Folder.Parent = workspace


while wait(Delay) do
    local RayNew = Ray.new(LocalPlayerGetMouse.Hit.Position, Vector3.new(0, 0, 0))
    Nil, Vector = workspace:FindPartOnRay(RayNew)
    local Part = Instance.new("Part")
    Part.Name = "Part" .. Number
    Part.Position = Vector
    Part.Velocity = LocalPlayer.Character.Head.CFrame.LookVector * PartVelocity + Vector
    Part.Parent = Folder
    Number += 1
en

If anyone could help that would be great!

I edited your code to shoot parts from the character’s head that travel towards Mouse.Hit.

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
local LocalPlayerGetMouse = LocalPlayer:GetMouse()

local PartVelocity = 1000
local Delay = 0

local Number = 1

local Folder = Instance.new("Folder")
Folder.Name = "Part's Folder"
Folder.Parent = workspace

while wait(Delay) do
	local Part = Instance.new("Part")
	Part.Name = "Part" .. Number
	Part.CanCollide = false
	
	Part.CFrame = LocalPlayer.Character.Head.CFrame
	Part.Velocity = CFrame.new(LocalPlayer.Character.Head.CFrame.p, LocalPlayerGetMouse.Hit.p).lookVector * PartVelocity
	--[[make a CFrame positioned at the head, then use lookVector to get the direction for velocity that points towards Mouse.Hit]]
	
	Part.Parent = Folder
	Number += 1
end