Beam not correctly at the position (Gun)

Hello, I would like to know how can I fix this little problem → the beam is not correctly on the ShootPos in my weapon, I do not know if I can fix it but if you have an idea tell me :

https://gyazo.com/87783cdbd079db7bd4d810ca08a83de2

Code (Client) :

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

local rs = game:GetService("ReplicatedStorage")

local pressing = false

local ColorAmmo = script.ColorAmmo
local DamageAmmo = script.DamageAmmo

local function CreateBullet(nameGun, pos, dmg, col, origplr)
	local char = origplr.Character
	local gun = char:FindFirstChild(nameGun)
	local cp = gun:FindFirstChild("ShootPos").CFrame.p
	local ray = Ray.new(cp, (pos - cp).unit * 300)
	local part, position = workspace:FindPartOnRay(ray, char, false, true)
	
	local beam = Instance.new("Part", workspace)
	beam.BrickColor = col
	beam.FormFactor = "Custom"
	beam.Material = Enum.Material.Neon
	beam.Transparency = 0.8
	beam.Anchored = true
	beam.Locked = true
	beam.CanCollide = false

	local distance = (gun:FindFirstChild("ShootPos").CFrame.p - position).magnitude
	beam.Size = Vector3.new(0.04, 0.04, distance)
	beam.CFrame = CFrame.new(cp, position) * CFrame.new(0, 0, -distance / 2)
	
	rs.Events.Items.Shoot:FireServer("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, part)
	
	game:GetService("Debris"):AddItem(beam, 0.05)
end

local function handleAction()
	pressing = true
	local char = plr.Character
	while pressing do 
		local isEquipped = char:FindFirstChild("ARI")
		local canShoot = rs.Events.Items.GetARICanShoot:InvokeServer()
		local isReloading = rs.Events.Items.GetARIReloading:InvokeServer()
		if isEquipped and canShoot and not isReloading then
			rs.Events.Items.ARIShoot:FireServer(pressing) -- Animation
			CreateBullet("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, plr)
			task.wait(0.05)
		end
	end
end

rs.Events.Items.Shoot.OnClientEvent:Connect(function(rename, repos, redmg, reammo, replr)
	CreateBullet(rename, repos, redmg, reammo, replr)
end)

mouse.Button1Down:Connect(handleAction)
mouse.Button1Up:Connect(function()
	pressing = false
end)

it maybe because your calling to fire to the server inside your create bullet if that is then returned to the client to call the create bullet again it maybe doubling over

also you should Parent the Beam after setting all the properties it will speed up the function a little

I am not sending 2 beams and I did not understand what you suggest.

the way you have that code it looks like it is calling it a 2nd time to display on this client

Server:

local rs = game:GetService("ReplicatedStorage")
local event = rs.Events.Items.Shoot

event.OnServerEvent:Connect(function(plr, gunName, posMouse, dmg, color, part)
	local char = plr.Character
	local gun = char:FindFirstChild(gunName)

	if gun then 
		if part then
			local humanoid = part.Parent:FindFirstChild("Humanoid")

			for _,p in pairs(game.Players:GetPlayers()) do
				if p ~= plr then
					event:FireClient(p, gun, posMouse, dmg, color, plr)
				end
			end

			if not humanoid then
				humanoid = part.Parent.Parent:FindFirstChild("Humanoid")
			end

			if humanoid then
				humanoid:TakeDamage(dmg)
			end
		end
	end
end)

Client:

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

local rs = game:GetService("ReplicatedStorage")

local pressing = false

local ColorAmmo = script.ColorAmmo
local DamageAmmo = script.DamageAmmo

local function CreateBullet(nameGun, pos, dmg, col, origplr)
	local char = origplr.Character
	local gun = char:FindFirstChild(nameGun)
	local cp = gun:FindFirstChild("ShootPos").CFrame.p
	local ray = Ray.new(cp, (pos - cp).unit * 300)
	local part, position = workspace:FindPartOnRay(ray, char, false, true)
	
	local beam = Instance.new("Part", workspace)
	beam.BrickColor = col
	beam.FormFactor = "Custom"
	beam.Material = Enum.Material.Neon
	beam.Transparency = 0.8
	beam.Anchored = true
	beam.Locked = true
	beam.CanCollide = false

	local distance = (gun:FindFirstChild("ShootPos").CFrame.p - position).magnitude
	beam.Size = Vector3.new(0.04, 0.04, distance)
	beam.CFrame = CFrame.new(cp, position) * CFrame.new(0, 0, -distance / 2)
	
	rs.Events.Items.Shoot:FireServer("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, part)
	
	game:GetService("Debris"):AddItem(beam, 0.05)
end

local function handleAction()
	pressing = true
	local char = plr.Character
	local humanoid = char:FindFirstChildOfClass("Humanoid")
	if humanoid then
		while pressing do 
			local isEquipped = char:FindFirstChild("ARI")
			local canShoot = rs.Events.Items.GetARICanShoot:InvokeServer()
			local isReloading = rs.Events.Items.GetARIReloading:InvokeServer()
			if isEquipped and canShoot and not isReloading then
				--rs.Events.Items.ARIShoot:FireServer(pressing) -- Animation
				humanoid:FindFirstChildOfClass("Animator"):LoadAnimation(script.Shoot_ARI):Play()
				CreateBullet("ARI", mouse.Hit.p, DamageAmmo.Value, ColorAmmo.Value, plr)
				task.wait(0.05)
			end
		end
	end
end

rs.Events.Items.Shoot.OnClientEvent:Connect(function(rename, repos, redmg, reammo, replr)
	CreateBullet(rename, repos, redmg, reammo, replr)
end)

mouse.Button1Down:Connect(handleAction)
mouse.Button1Up:Connect(function()
	pressing = false
end)