PT-BR EN ES
Channel Icon

Crazy Ozz

Official Channel Website

Command Block

How to Detect Players in Water in Minecraft (Command Block)

Minecraft Java Edition 1.21+ and 26+ – Scoreboard Timer + Execute if Block Water Tutorial

In this tutorial, you will learn how to detect when a player is inside water in Minecraft using command blocks. This system works in Minecraft Java Edition 1.21+ and 26+ and uses a scoreboard timer to count how long the player stays in water. With this method, you can run commands after a specific time, such as dealing damage, teleporting, giving effects, or activating functions for adventure maps, minigames, and custom servers.

To start, let's create this scoreboard that will track the time spent in water

scoreboard objectives add time_in_water dummy

If you want to see how long the player has been in water, you can use this command

scoreboard objectives setdisplay sidebar time_in_water

Every 20 points in the scoreboard equals 1 second in water, meaning a value of 60 equals 3 seconds, and so on

Now we need to detect when the player is in water and start counting

To do this, place the following command in a Repeat command block set to Always Active

execute as @a at @s run execute if block ~ ~ ~ water run scoreboard players add @s time_in_water 1

The command below will execute a function after the player stays in water for more than 3 seconds

execute as @a if entity @s[scores={time_in_water=90..}] run function comandos:time_in_water

The function will reset the timer and apply damage to the player

You can replace it with another command after run

Download the function I created by clicking here

Don’t know what a function is or how to create one? Check out this tutorial on the site by clicking here

Want cheap and lag-free Minecraft hosting?

I recommend Sparked Host: affordable plans, great performance, easy panel and fast support.

πŸš€ Start your Minecraft Server

Still have questions? Watch the video below