# Do command blocks stop working at a certain distance?

This is regarding Minecraft: Bedrock Edition. I am trying to automatically change players to adventure mode when when entering a town and back to survival mode when leaving. I created a function which is executing in a repeating command block. The below commands basically create 2 towns. If player 1 goes into player 2 town it puts them in adventure mode. When player 1 enters their own town it puts them in creative mode. Leaving both towns will put them in survival mode.

#run this one time to create a townMode variable

scoreboard players set @a[scores={townMode=!0}] townMode 0

#town for player 1
scoreboard players set @a[name=player1name, scores={townMode=!1}, x=501, y=62, z=151, dx=49, dy=49, dz=49] townMode 1
scoreboard players set @a[name=!player1name, scores={townMode=!2}, x=501, y=62, z=151, dx=49, dy=49, dz=49] townMode 2

#town for player 2
scoreboard players set @a[name=player2name, scores={townMode=!1}, x=501, y=62, z=93, dx=49, dy=49, dz=49] townMode 1
scoreboard players set @a[name=!player2name, scores={townMode=!2}, x=501, y=62, z=93, dx=49, dy=49, dz=49] townMode 2

gamemode 0 @a[scores={townMode=0},m=!0]
gamemode 1 @a[scores={townMode=1},m=!1]
gamemode 2 @a[scores={townMode=2},m=!2]

Its basically working BUT I noticed that the command block stops executing the commands if I am too far away. If I put the command block in the center of the town it works but if I put it really far away it doesn't seem to trigger consistently. I noticed this after a few hours beating my head against the table. I saw via commandblockoutput the commands stop running if I'm too far from the command block. Is there any workaround where I can have the command block far from the villages but still work?

• If the chunks aren't always loaded, the command blocks there will stop running. Jan 10, 2021 at 23:28

Command blocks follow the same rules as other blocks, in that they will stop running if the chunk they are located in is unloaded.

This question asked something similar. One solution that was suggested there, by @MBraedley:

The chunks surrounding the world spawn are always loaded, so this is the best place to put command blocks that you always want to run. You can change where the world spawn is using the /setworldspawn command.

• Dude that is a pro tip thanks! Will try it out and give the credit if it works. Was worried I would have to put command blocks every 50 squares in the whole world Jan 12, 2021 at 1:37
• Glad I could help :) Jan 12, 2021 at 1:55

Alas in bedrock command blocks do not stay loaded when you get too far away even if placed in the world spawn area. I tried it experimentally and the commands stop running if I get too far away. I however did find this post which says you can add up to 10 'ticking areas'. This works like a charm in bedrock! Will upvote the answers since the do look like they would work in java edition and you led me in the right direction.

/tickingarea x1 y1 z1 x2 y2 z2 chunkName

• Ahh, this makes sense! This is a great solution, if you want you can checkmark yourself :D Jan 12, 2021 at 3:35