There is an event sheet action that lets you set a yarn variable - it takes two parameters: the name of the variable and the value. Please read the documentation
Sorry I misread your comment. Bondagejs (the parser gdevelop uses) doesnt yet support displaying yarn variables as text, so the player name syntax doesnt yet exists as a feature.
I raised a ticket for it and if bondagejs author is interested in having it, I might do a pr to add it. It has been requested many times over the years.