"User Block" redirects here. For the feature this one replaced, see User ID (block).
Category Sensing
Type Reporter
Introduced in 2.0

The Username block is a sensing block and a reporter block. It reports the username of the user viewing the project, which can be used for saving progress in a project, either with a variable encoder or cloud lists (once they are released with string-storage capabilities), as well as other purposes. If a user is not signed in, this block returns the empty string.


The warning.

Originally, the Scratch Team was reluctant to add this block because it could compromise users' privacy.[1] They started with the User ID block, which gave an anonymous but effective way of recognizing users for a specific project. However, they eventually decided to replace it with this block because it is easier for beginners to understand and was so frequently requested.[citation needed]

All projects that contain the username block will notify the user playing the project of it. However, it is possible to play a project anonymously by signing out before using it, although this means that some features such as cloud data will not be available. There used to be a bug which caused the message to appear if the backpack had a script with the username block inside it, even if the project did not contain the username block.[2]

Potential Abuses

There are potential abuses of this block, such as hiding content (or selectively showing disrespectful/inappropriate content) to certain users. If a user finds a project containing a potential abuse of this block, they should report the project.

Example Uses

  • Greeting a user who visits a project
say (join [Hi, ] (username))
  • Checking if the user has visited before, using cloud data. Cloud lists are not an official feature in Scratch, but they are often simulated with numerical encoding.
if <not <[☁ visitors v] contains (username)>> then
  add (username) to [☁ visitors v]
  say (join[Hi,](join(username)[!]))
  say (join[Welcome back again, ](join(username)[!]))
  • Checking if the viewer is logged in
when green flag clicked
if  <(username) = []> then//a logged off user reports a blank response
say [Hi, new user!] for (2) secs
when gf clicked
set [chars v] to [� !"#$%&'()*+,-./:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~0123456789
set [item v] to (1)
repeat (length of(chars::variables))
add (letter (item) of (chars::variables)) to [chars v]
change [item v] by [1]
if <<not <(username) = []>>and<not<[users v] contains (username)?>>> then //checks if the user is logged in to Scratch and not in the leaderboard
add (username) to [users v]
add [0] to [scores v] //in which "0" is the initial score
if <[users v] contains (username)> then //checks if the user has been added to the leaderboard already
set [i v] to [1] //begin with the first list item
repeat until <(item (i) of [users v]) = (username)> //the deletion process
change [i v] by (1)
delete (i) of [users v]
delete (i) of [scores v]
set [i v] to [1]
repeat until <<(i) > (length of [scores v])> or <(score) > (item (i) of [scores v])>> //the variable "score" is the latest score of the user
change [i v] by (1) //it will end at the proper list location
insert (username) at (i) of [users v]
insert (score) at (i) of [scores v]
  • Creating a VIP system
when gf clicked
if <[VIPs v] contains (username)> then
say [You are an VIP]
set [Is VIP? v] to [y]
say [Sadly, you are not a VIP]
set [Is VIP? v] to [n]

See Also

  • User ID — this block's predecessor


Cookies help us deliver our services. By using our services, you agree to our use of cookies.