Issue with /setblock & /tp @p
I am creating and adventure map and I have this shop to where players can teleport to by pressing a button.
So when they press the button it activates two command block:
/tp @p 1016 56 -4060 # Teleports closest player to the shop
/setblock 1015 57 -4063 command_block 0 destroy {Command:"/tp @p[r=3] 1019 56 -4068"}
# This is supposed to create a command block connected to a button in the shop that lets the player go back to their last position.
However, the last command never runs and the Command Block is not created. If I remove the radius limitation, though, it creates the command block, but instead of it having "/tp @p[r=3] 1019 56 -4068", it has "/tp Edoreld @p[r=3] 1019 56 -4068", where Edoreld is my username. What I would like for it to do is not to expand my username. Is that possible?
Best Answer
Okay I tried to rebuild this like you described. I did not tried the first tp command I hope this one is working.
Everything I describe here is running in a clean Minecraft 1.8 on a offline map with cheats activated.
The setblock command should look like this:
setblock -30 79 214 command_block 0 replace {Command:"/tp @p[r=3] -28 79 214"}
If you use the command like that it should working as you described. But I do not know what you actully made wrong... The commandblock should be created also with the @p[r=3] or only a @p inside. It is not possible that the @p is changed to the playername.
This commandblock is configured with the command from above.

This will create a other commandblock two blocks to the left. With the command /tp @p[r=3] -28 79 214 as configured in the first command.

Keep in mind that you have to stay three blocks near the commandblock that is spawing (the right one)!
Otherwise you are not teleported because of the radius limitation you programmed into the commandblock. If three blocks are not enough you have to increase the number or programm a exact block teleport (if it is possible that other players are selected with a bigger radius).
Pictures about "Issue with /setblock & /tp @p"



Why is my teleport command block not working?
You'll need to replace the @s with either your in-game name, or @a for all players. If you want it to teleport only the person who activates the command block then that might work with @p, or you may need an /execute command that uses a target selector argument .What is the command for Setblock in Minecraft?
How to Enter the CommandHow do you use the Setblock command in Minecraft bedrock edition?
You can use the /teleport command to teleport a player or entity to a set of coordinates in the game (see also /tp command).Set block/fill command tutorial for Minecraft PE
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Alex Green, SHVETS production, Alex Green, Alex Green
