I want to write my first scientific paper, but I'm worried it'll get rejected by the journal. Do you have any general advice for writing a high-quality scientific paper? I'd also appreciate advice on academic formatting and referencing.
Most scientific papers follow the same structure, following it would increase the chance of getting accepted.

Title page: Your front page should contain a running title in a top corner, with your paper's title, authors and institution centered in the middle.

Abstract: You should include a brief summary, around 300 words long of what your paper is about, its purpose and what you found out. This section should give the reader enough information to know if your paper is of interest to them.

Introduction: This section includes the relevant background information about the topic your paper is on. Why you are conducting your study should be included, along with your initial research question. Try not to repeat what you wrote in the abstract, and add more depth instead.

Method: Here you should explain the step-by-step process of your investigation, why you did what you did, as well as some information on how you analysed your obtained results. Keep it succinct, so that that a reader could easily reproduce your steps, as if it was a cooking recipe.

Results: Explain what factually supported findings your investigation uncovered. Include labelled graphs, diagrams and other supporting evidence throughout this section. Label all of your figures clearly (Table 1, Table 2 etc), so that they can be referenced in other parts of your paper. But make sure you don't try to draw any conclusions in this section, only explain what the data directly tells you.

Discussion: Here you try to extrapolate and draw any meaning from your data. This includes how it relates to the real world, what things mean, and what would be expected to happen if your findings were applied in practice. If there are any, point out any outliers or anomalies. But most importantly, be very clear about the conclusions you are drawing from your data.

References: In order to make your scientific paper appear credible, it is crucial to reference all of your sources in an accepted format. Commonly APA, MLA or CMS referencing is used. This process is often time consuming, so using a reference generator can be useful. Include the authors name, date accessed, link, as well as other features. A typical APA citation looks like this:

Author. (Date). Title [Format]. Source.
Source: Publication Manual, 1.2

Some other general tips include writing impersonally, using past tense and having consistent formatting throughout your paper. Use size 11 or 12 font, in Times New Roman or Cambria. Include 1 (2.5cm) margins on all sides of your page. As well as page numbers, along with subheadings for the relevant sections.
Are there any specific guidelines to avoid rejection by the journal?