Tracer's Not Connecting When Player Is Moving

Hi,

I made a gun with tracers, but when the player moves it doesn’t connect to the tip of the gun.

Example:
– Attachment (Muzzle) is shown in the video

Script Responsible For Tracers:

local function firing(plr, unitray)
	if not equipped or not plr.Character then return end
	
	canFire.Value = false
	
	local ray = Ray.new(unitray.Origin, unitray.Direction * 10000)
	local hit, pos = workspace:FindPartOnRayWithIgnoreList(ray, {plr.Character, workspace:WaitForChild("Bullets")})
	
	if hit then
		if hit.Parent and hit.Parent:FindFirstChild("Humanoid") then
			hit.Parent.Humanoid:TakeDamage(35)
		end
	end
	
	local fireSound = barrel:WaitForChild("Fire"):Clone()
	fireSound.Parent = barrel
	fireSound.PlayOnRemove = true
	fireSound:Destroy()
	
	barrel:WaitForChild("Muzzle"):WaitForChild("Fire"):Emit(1)
	
	local function createTrace(pos1, pos2)
		local p1 = game.ReplicatedStorage:WaitForChild("InvisPart"):Clone()
		p1.Parent = workspace.Bullets
		p1.Position = pos1
		local p1A = Instance.new("Attachment", p1)

		local p2 = game.ReplicatedStorage:WaitForChild("InvisPart"):Clone()
		p2.Parent = workspace.Bullets
		p2.Position = pos2
		local p2A = Instance.new("Attachment", p2)

		local trace = Instance.new("RodConstraint", workspace.Bullets)
		trace.Attachment0 = p1A
		trace.Attachment1 = p2A
		trace.Visible = true
		trace.Color = BrickColor.new("Cool yellow")

		game:GetService("Debris"):AddItem(p1, 0.2)
		game:GetService("Debris"):AddItem(p2, 0.2)
		game:GetService("Debris"):AddItem(trace, 0.2)
	end
	
	if pos then
		createTrace(barrel.Muzzle.WorldPosition, pos)
		print(barrel.Muzzle.WorldPosition)
	else
		createTrace(barrel.Muzzle.WorldPosition, ray.Origin + ray.Direction.magnitude * ray.Direction.Unit)		
		print(barrel.Muzzle.WorldPosition)
	end
	
	wait(coolDown)
	
	canFire.Value = true
end

--// Events \\--

-- Activating --
fireEvent.OnServerEvent:Connect(firing)

One of the attachments in createTrace must be the attachment at the tip of the gun.

but one of them is already the attachment at the tip of the gun