Minecraft – How to give a player an effect when standing bedrock

minecraft-commandsminecraft-java-edition

I'm making a map. And I want to give the player levitation when standing on bedrock.

I tried this command:

execute @p ~ ~ ~ detect ~ ~-1 ~ minecraft:bedrock effect @a minecraf:levitation 30

But I constantly get this error:

[13:02:26] Failed to execute 'detect' as F1NN3RT

What am I doing wrong?

Best Answer

The syntax of execute detect is:

/execute <entity> <x> <y> <z> detect <x> <y> <z> <block> <dataValue|blockState> <command>

You need a data value or block state (e.g: 0 or default) after minecraft:bedrock.

You've missed the t in minecraf:levitation.

You're also executing from @p but affecting @a. This would mean that if the closest player to the command block stands on bedrock, everyone will get levitation. Instead, you should make everyone (/execute @a) give themselves levitation (/effect @a[c=1], to select theirself even if they're dead).

Try:

execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:bedrock 0 effect @a[c=1] minecraft:levitation 30