Gun beam doesnt come our of GunPoint

So I made a gun script where the beam comes out of the GunFirePoint Attachment in front of the gun. But if I try to click. The beam comes from the middle of the baseplate. Any help? Client Script:

local tool = script.Parent

local FirePoint = tool.Handle:FindFirstChild("GunFirePoint")

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()
local BulletFolder = game.Workspace.Bullets
local BulletFireEvent = game.ReplicatedStorage.GunRemotes.MegaGun.MegaGunFire

local MousePosition = mouse.Hit.p
local FirePosition = FirePoint.Position
BulletFireEvent:FireServer(MousePosition, FirePosition)

This is the server script:

--Mega Gun
local MegaGunEvent = game.ReplicatedStorage.GunRemotes.MegaGun.MegaGunFire
local BulletFolder = game.Workspace.Bullets
local debris = game:GetService("Debris")

local range = 200

local function CreateBeam(FirePoint, direction)
	local midpoint = FirePoint + direction/2
	local part ="Part")
	part.Parent = BulletFolder
	part.Anchored = true
	part.CanCollide = false
	part.Material = Enum.Material.Neon
	part.BrickColor ="Really red")
	part.CFrame =, FirePoint)
	part.Size =, .5, direction.magnitude)
	debris:AddItem(part, 1)

MegaGunEvent.OnServerEvent:Connect(function(player, mousePos, firepointPos)
	local Direction = (mousePos - firepointPos).Unit * range
	local Result = workspace:Raycast(firepointPos, Direction)
	if Result then
	CreateBeam(firepointPos, Direction)

Your “midpoint” maths is off;
start by setting the part size before setting the cframe, then do this:
part.CFrame =, direction) *, 0, part.Size / -2)