Attachment for beam spawns with a huge offset

So, I’m working on creating a gun system for a game. It uses beams for the bullet effect, but the attachment for the beam spawns at a huge offset:

Video Demonstrating:

And here is my coding: (EDIT: Its attachment 2 that spawns with the offset)

GunEvent.OnServerEvent:Connect(function(Player, MouseTargetFilter, MouseHit, OriginPos, OriginCFrame)
		local Raycast =, (MouseHit - OriginPos).Unit * GunModule.Range)
		local PartsOnRay, Position = workspace:FindPartOnRay(Raycast, Player.Character, false, true)

		local Part ="Part", workspace)
		Part.Size =, 0.1, 0.1)

		local Attachment1 ="Attachment")
		local Attachment2 ="Attachment")
		local Beam ="Beam", workspace)

		Part.Position = MouseHit
		Part.Anchored = true
		Part.CanCollide = false
		Part.Transparency = 1

		Attachment1.CFrame = Part.CFrame
		Attachment1.Parent = Part

		Attachment2.CFrame = OriginCFrame
		Attachment2.Parent = Player.Character[script.Parent.Parent.Parent.Name].GunParts.Origin
		Beam.Attachment0 = Attachment1
		Beam.Attachment1 = Attachment2
		Beam.Width0 = 0.2
		Beam.Width1 = 0.2
		Beam.FaceCamera = true
			deleteBullet(Attachment1, Attachment2, Beam, Part)

		local Humanoid = PartsOnRay.Parent:FindFirstChild("Humanoid")

What is the input for origincframe?


You think you could pre-add an asset of the bullet with the attachment and the attachment on the nozzle of the gun? Could that prevent the offset issue?

Note: The bullet can get cloned later on

I think he could just put an attachment on the gun which is the barrel. yea
(edit the attachment would have to be cloned before making the bullet)

That worked, but now the other attachment has an offset, the part spawns where the mouse clicks, but the attachment doesnt.

Edit, I managed to fix it by remaking the part and attachment and cloning it into workspace when needed.