Skip to main content

How do you run code when a player spawns?



  • Dan Noble

    Great question, Asha! 

    The best way I can think of doing this would be with command blocks and using some commands. First you'll need to give yourself a command block as they aren't available in the inventory. To give yourself a command block, while in game type: /give @s command_block 

    We're going to use a couple of command blocks and a comparator with the /testfor and /title commands. 

    Arrange the command blocks and comparator like this: 

    Right click on the first command block. Set the settings to Block Type: Repeat, Redstone: Always Active. Type /testfor @p [r=3] into the Command Input.

    Right click on the second command block. Type: /title @a title Welcome! into the Command Input. 

    You can change the welcome! part of that line to whatever you like to display. I'd bury this under the spawn point so whenever anyone shows up, it will display your message. 

    Hope this helps!

  • Asha Hendrickson

    Thank you! I did think of that but I didn't know how to use the command block well enough. Also, is there a way to do that if they spawn somewhere else, because they already played in the world?

  • Dan Noble

    Not that I've been able to discover. 

    If it's a world that you're hosting, you could use the /tp command to teleport all the students back to the spawn point (also possible with the Classroom Mode utility) which would place them within the radius of the /title command block sequence. 



Please sign in to leave a comment.