Turret not rotating

I am trying to make a turret rotate towards the mouse ,I eventually want the gun to adjust on the Y axis also.

Client: 
local UIS = game:GetService("UserInputService")
local Players = game:GetService("Players")
local Rep = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")


local plr = Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local Event = Rep.Communications.Guns.aim

local function worldMouse(X,Y)
    local ScreenRay = cam:ScreenPointToRay(X, Y)
    local Ray = game.Workspace:Raycast(ScreenRay.Origin, ScreenRay.Direction * 1000)
    if Ray then
        print(Ray.Position)
        return Ray
    end
end

RS.Heartbeat:Connect(function()
    local CursorPosition = UIS:GetMouseLocation()
    Event:FireServer(worldMouse(CursorPosition.X, CursorPosition.Y))
end)

Server:
-- This is the code that should move it, but it doesnt.
    local gun = workspace.FrontGun
    local MyX = (mousepos.X - gun["ship gun"].Base.Attachment0.WorldPosition.X)
    local MyY = (mousepos.Y - gun["ship gun"].Base.Attachment0.WorldPosition.Y)
    local Theta  = math.atan2(MyX, MyY)
    gun["ship gun"].gun.Union.HingConstraint.TargetAngle = math.deg(Theta)```
[dsfsd23.rbxm|attachment](upload://6CdeDRnSkhYVq5nZWOX7h5JsayN.rbxm) (76.0 KB)

Instead of using the worldMouse function you made use

First get the mouse variable.

local mouse = plr:GetMouse()

Then we will get the position which the mouse hits:

mouse.Hit -- CFrame value

Now to make the turret look out the mouse use:

-- I am assume all other parts are welded to this part and all are unanchored
TurretPrimaryPart.CFrame = CFrame.new(TurretPrimaryPart.Position, mouse.Hit.Position)

How does this work with a hinge