Tellraw or a message in chat at a certain 𝑦 level in Minecraft Bedrock?

Solution 1:

You can target players within a volume by using the target selector arguments x, y, z, dx, dy, and dz.

First, to prevent the players from being spammed with tellraw messages, you need to create a scoreboard objective that keeps track of whether the player has been warned or not:

/scoreboard objectives add shownWarning dummy

Then, put the following command in a repeating, unconditional, needs redstone command block...

execute @a[scores={shownWarning=0}] ~ ~ ~ execute @s[x=~,y=63,z=~,dx=0,dy=-<number of blocks>,dz=0] ~ ~ ~ tellraw @s {"rawtext":{"text":"You are about to hit the death barrier."}}

...where <number of blocks> is the number of blocks before y=63 where you want to warn the players. This command shows the players who haven't been shown the warning and are in the warning volume the tellraw message.

Put the following in a chain, conditional, always active command block that the first command block is facing. This will set the shownWarning objective of the players who have been told the message to 1, which means they have been shown the warning.

execute @a[scores={shownWarning=0}] ~ ~ ~ execute @s[x=~,y=63,z=~,dx=0,dy=-<number of blocks>,dz=0] ~ ~ ~ scoreboard players set @s shownWarning 1

Finally, put the following in a repeating, unconditional, needs redstone command block. This will reset the shownWarning of the players who are outside of the warning zone.

execute @a[scores={shownWarning=1}] ~ ~ ~ execute @s[x=~,y=<62.90 - <number of blocks>>,z=~,dx=0,dy=-<number of blocks>,dz=0] ~ ~ ~ scoreboard players set @s shownWarning 0

For example, if the number of blocks is 5, the execute @s part of the command would be:

execute @s[x=~,y=57.90,z=~,dx=0,dy=-5,dz=0] ~ ~ ~

Link all of the repeating command blocks to a daylight sensor (using redstone) or whatever you are using to detect if it is daytime.


Explanation

Without the scoreboard objective, there would be no way to keep track if a player has already seen the warning. Otherwise, any player within the warning zone would be spammed with messages.

The reason why the commands are split up into execute @a[scores=... execute @s[x=~... and not combined like execute @a[scores=...,x=~...] is so that the ~ is set to the location of the player, not the command block.

First command

  • execute @a[scores={shownWarning=0}] ~ ~ ~ Execute as all the players who have not been shown the warning (shownWarning=0).
  • execute @s[x=~,y=63,z=~,dx=0,dy=-<number of blocks>,dz=0] ~ ~ ~ Execute if the player is also within the volume between y=63 and y=63 - <number of blocks>. As x, z, dx, and dz are also required when using y and dy, they are set to test if the player is in the x and z coordinates of the player (which will always be the case).
  • tellraw @s {"rawtext":{"text":"You are about to hit the death barrier."}} The tellraw message.

Second command

  • execute @a[scores={shownWarning=0}] ~ ~ ~ Same as the first command.
  • execute @s[x=~,y=63,z=~,dx=0,dy=-<number of blocks>,dz=0] ~ ~ ~ Same as first command.
  • scoreboard players set @s shownWarning 1 Sets the players who have not been shown the warning and are in the warning zone's shownWarning to 1. This is so they don't get spammed with messages. This command occurs after the first command (because it's a chain command block).

Third command

  • execute @a[scores={shownWarning=1}] ~ ~ ~ Execute as all the players who have been shown the warning (shownWarning=1).
  • execute @s[x=~,y=<62.99 - <number of blocks>>,z=~,dx=0,dy=-<number of blocks>,dz=0] ~ ~ ~ This is similar to the other commands except for the volume that it's testing. Instead of testing if the player is in the warning zone, it is testing if it is below it. The reason why y is 62.99 - <number of blocks> is because it is 0.01 blocks below the start of the warning zone.
  • scoreboard players set @s shownWarning 0 Sets the players who are outside of the warning zone's shownWarning to 0, which allows them to see the warning again if they enter get close to the death barrier.

Because you mentioned that you're brand new to using command blocks, here are some pages on the Minecraft wiki that you can read for more information:

  • Scoreboard
  • execute
  • tellraw (Raw JSON text in BE)