You need to know a few things before you can play scales (let's focus on major and minor scales for this "lesson"):
1) You need to know the number of half-steps between adjacent notes in the scale. For major scales, the notes are one step (two half steps) apart except between the degrees 3-4 and 7-8 where it's only one half step. For minor scales, the notes are one step (2 half steps) apart except between the degrees 2-3 and 5-6 where it's only one half step. This is absolutely necessary to know!
2) You need to know that there's a half step between the notes E and F and the notes B and C. All other adjacent non-accidental notes (neither sharp, nor flat) are one step apart. That will enable you to find the tonic of the scale you want to play. After that, you don't really need that knowledge.
3) You need to know the notes the open strings play. It's E-A-D-G-B-E (a mnemonic for it is "Every Apple Does Go Bad Eventually") where:
E is the 6th string (pitched the lowest, thickest, closest to ceiling)
A is the 5th string
D is the 4th string
G is the 3rd string
B is the 2nd string
E is the 1st string (pitched the highest, thinnest, closest to floor)
4) You need to know that a fret on the guitar neck represents one half step. More precisely, two adjacent frets are one half step apart in terms of pitch.
5) You need to know the fret that gives you the note that's one step away (ascending) on the next string. It's always three frets away (toward the headstock) except when you go from the 3rd to the 2nd string where it's only two frets away. An open string counts as one fret.
6) You need to know the fret that gives you the note that's one half step away (ascending) on the next string. It's always four frets away (toward the headstock) except when you go from the 3rd to the 2nd string where it's only three frets away. An open string counts as one fret.
Armed with this knowledge, you can play any (major or minor) scale on your guitar by just counting the frets.
Say, for example, you want to play the C major scale on your guitar:
1) Where is C? We're gonna locate C on the A string, that is, the 5th string. A and B are one step apart so B is on the 2nd fret. B and C are one half step apart so C is on the 3rd fret. You are now at the scale tonic, that is, degree 1. All you need to do now is remember the spacing step-wise of the scale degrees and count the frets to go from degree to degree as intelligently as possible, that is, changing strings whenever it makes sense. You absolutely don't need to know the names of the notes on the fretboard at this point. Here, we are gonna play in the 1st position, meaning we want to play frets 0 (open string), 1, 2, and 3 with the index on the 1st fret, the major on the 2nd fret, and the ring finger on the 3rd. The goal is to have your hand move as little as possible on the fretboard by playing over 4 frets.
2) Where is degree 2? Degree 2 is one step away from degree 1 and is therefore on the 0th fret (open string) of the 4th string (the D string).
3) Where is degree 3? Degree 3 is one step away from degree 2 and is therefore on the 2nd fret of the 4th string.
4) Where is degree 4? Degree 4 is one half step away from degree 3 and is therefore on the 3rd fret of the 4th string.
5) Where is degree 5? Degree 5 is one step away from degree 4 and is therefore on the 0th fret (open string) of the 3rd string (the G string).
6) Where is degree 6? Degree 6 is one step away from degree 5 and is therefore on the 2nd fret of the 3rd string.
7) Where is degree 7? Degree 7 is one step away from degree 6 and is therefore on the 0th fret (open string) of the 2nd string (the B string).
8) Where is degree 8? Degree 8 is one half step away from degree 7 and is therefore on the 1st fret of the 2nd string.
Here's what your hard work has produced! The black numbers indicate the guitar strings (the 6th string or E low is the bottom string but is the one closest to the ceiling when you actually hold a guitar). The red numbers on the fretboard indicate the degrees of the C major scale (they absolutely don't represent fingering).
You can keep going like this until you run out of strings and you can also go backwards from the tonic, again until you run out of strings the other way. As you can see, you have a limited number of scale notes to work with in your solos but it's a pretty good start.
You can do that very same exercise for any tonic (also known as root) and any type of scale (major or minor). I believe it's simpler to only look at the degrees within the scale, not the actual note names (except for the tonic). Well, at least, until you are more familiar with where the notes are on the fretboard.
There's no real wrong way to play scales as you can do whatever you want as long as you play the right notes, even if it means playing all the scale notes on one single string and (the horror!) one finger.
For reference, this is the exact same C major scale as shown above, except that it is played in the 2nd position (no open strings). The neat thing is that you can play this pattern up and down the fret board and you'll always play a major scale (different roots).