Minecraft – Why isn’t the Minecraft detect command working when executed by a command block

minecraft-commandsminecraft-java-edition

I now have this command:

/execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:sandstone 0 effect @a[c=1] minecraft:slowness 2 1

When I run this from the chat it works fine, it gives me slowness when I stand on sandstone and no slowness when I don't. but when I run this from a command block, it says

Failed to execute 'detect' as [my name]

Why is this? Why won't my command work when executed by a command block?

Best Answer

As Fabian commented, use @s target selector, instead of the @a[c=1]. This target selector selects the entity executing the command. You are using the execute command so this would select the player that has sandstone beneath them.


This 'error' is indicating that the detect portion did not detect sandstone below the player.

It will say this every time it executes and it does not detect sandstone, I am standing on stone here:
Error

Exact same command while standing on sandstone, no error and I have slowness:
Non Error