I have just created a Minecraft server to play with friends, but I would like to make sure that every time a player joins the server they spawn directly at spawn, instead of the last position they were in. Is there any way that I can do this?
If you're using a bukkit based server (bukkit, spigot, paper, etc) you can use EssentialsX and EssentialsX spawn.
config.yml you should go to
spawnpoint: <SPAWNPOINT NAME>
spawns yml you can manage your spawns.
In your permissions plugin (I recommend luckperms) you can then set spawnpoints and exceptions per-group or per-player.
I recommend reading the documentation of the plugins and watching a tutorial if you're new to plugins.
If not using a plugin supporting server, you're probably limited to commandblock trickery.