local Players = game:GetService("Players")
local player = Players.LocalPlayer

-- Wait for 2 seconds after joining
task.wait(2)

-- Function to create a draggable part for movement
local function createDraggablePart(color, axis, hat)
    local part = Instance.new("Part")
    part.Size = Vector3.new(1, 1, 1)
    part.Shape = Enum.PartType.Ball
    part.Color = color
    part.Anchored = true
    part.CanCollide = false
    part.Parent = workspace

    -- Function to update the draggable part's position relative to the hat
    local function updatePartPosition()
        if hat:FindFirstChild("Handle") then
            if axis == "X" then
                part.Position = hat.Handle.Position + Vector3.new(3, 0, 0)
            elseif axis == "Y" then
                part.Position = hat.Handle.Position + Vector3.new(0, 3, 0)
            elseif axis == "Z" then
                part.Position = hat.Handle.Position + Vector3.new(0, 0, 3)
            end
        end
    end

    -- Mouse drag handling
    local mouse = player:GetMouse()
    local moving = false

    mouse.Button1Down:Connect(function()
        if mouse.Target == part then
            moving = true
        end
    end)

    mouse.Button1Up:Connect(function()
        moving = false
    end)

    game:GetService("RunService").RenderStepped:Connect(function()
        if moving then
            local mousePos = mouse.Hit.Position
            local newPos = part.Position

            if axis == "X" then
                newPos = Vector3.new(mousePos.X, part.Position.Y, part.Position.Z)
            elseif axis == "Y" then
                newPos = Vector3.new(part.Position.X, mousePos.Y, part.Position.Z)
            elseif axis == "Z" then
                newPos = Vector3.new(part.Position.X, part.Position.Y, mousePos.Z)
            end

            part.Position = newPos
            if hat:FindFirstChild("Handle") then
                hat.Handle.Position = newPos - (axis == "X" and Vector3.new(3, 0, 0) or
                                               axis == "Y" and Vector3.new(0, 3, 0) or
                                               Vector3.new(0, 0, 3))
            end
        end
    end)

    -- Keep updating the draggable part's position relative to the hat
    game:GetService("RunService").Heartbeat:Connect(updatePartPosition)

    return part
end

-- Select a random hat
if player.Character then
    local hats = {}
    for _, accessory in pairs(player.Character:GetChildren()) do
        if accessory:IsA("Accessory") then
            table.insert(hats, accessory)
        end
    end

    if #hats > 0 then
        local selectedHat = hats[math.random(1, #hats)]

        -- Create draggable parts for the hat
        if selectedHat:FindFirstChild("Handle") then
            local xPart = createDraggablePart(Color3.fromRGB(255, 0, 0), "X", selectedHat)
            local yPart = createDraggablePart(Color3.fromRGB(0, 255, 0), "Y", selectedHat)
            local zPart = createDraggablePart(Color3.fromRGB(0, 0, 255), "Z", selectedHat)

            -- Position the draggable parts initially
            xPart.Position = selectedHat.Handle.Position + Vector3.new(3, 0, 0)
            yPart.Position = selectedHat.Handle.Position + Vector3.new(0, 3, 0)
            zPart.Position = selectedHat.Handle.Position + Vector3.new(0, 0, 3)
        else
            warn("Selected hat does not have a Handle!")
        end
    else
        warn("No hats found!")
    end
else
    warn("Character not loaded!")
end

Hello ChatGPT, i hope you're having a nice day. i would like to request something of you. could you fix this issue: basically, if you're dragging one of the parts and move your mouse off the part while dragging it, the position completely gets set completely incorrectly, like 50 studs away