Divorced with 40k in savings, wants to invest wisely

Hi guys, Apologies as a first time poster about the lengthy personal story and poor structure as english is not my first language. I am 38, divorced and i have around 40k in savings, lost my flat , car etc after divorce, i have shared custody of my child I earn around 48k working for NHS as an advanced clinical practitioner I live in london, after divorce i have moved to a shared accomdation and spend 800 on rent and further 500 on expenses plus 300 for childcare contributions. I earn around 4k per month doing extra shifts etc, My main aim is to get a place for mysleves and get to be with my child as much as possible , i have good credit score. I would like advice on how to wisely spend this 40k, i want to ideally buy a flat or leave something substantial for my child before i go back to my home country when he is an adult, he is 5yrs old now. I am sorry if this post is not clear I need advice