Why my gun fires bullet in the wrong direction?

I am trying to make a gun, but the problem is that the bullet fires in the wrong direction.
(Also this is just practice on how to make guns so there is no delay.)

Can anyone tell me what is the problem and how I can fix it?

LocalScript:

local Tool = script.Parent
local Fire = script.Parent:WaitForChild("Fire")
local Mouse = game.Players.LocalPlayer:GetMouse()

Tool.Activated:Connect(function()
	local ray = Ray.new(Tool.Handle.Barrel.Position,(Mouse.Hit.Position-Tool.Handle.Barrel.Position).Unit*500)
	local part,position = workspace:FindPartOnRay(ray,game.Players.LocalPlayer.Character,false,true)
	Fire:FireServer(part,position)
end)

ServerScript:

local Fire = script.Parent.Fire
local tool = script.Parent

Fire.OnServerEvent:Connect(function(player,part,position)
	local cl = script.Parent.Bullet:Clone()
	cl.CFrame = script.Parent.Handle.Barrel.CFrame*CFrame.new(-cl.Size.X/2,0,0)
	cl.CFrame = CFrame.new(cl.Position,position) -- The problem lies here I think?
	cl.Parent = workspace
	
	spawn(function()
		while cl do
			cl.CFrame = cl.CFrame * CFrame.new(-1,0,0)
			wait()
		end
	end)
	
	wait(2)
	cl:Destroy()
	cl = nil
end)

Thanks!

I found the solution myself. Bullet’s LookVector was wrong!

Fixed it by multiplying the CFrame by CFrame.Angles(0,math.rad(-90),0)

3 Likes