How do I give players a potion effect when they reach a certain XP level?

Solution 1:

Basics

Place a repeating command block and set it to Always Active. In the command input, type:

/effect @a[lm=10,l=20] speed 1

This will effect all players with a status effect between 10 and 20 levels with speed.

Repeat but change the lm and l numbers to set the level where the effect is applied. lm is the minimum amount needed to trigger, l is the maximum.

Things You Can Change

Change the 2nd number after speed to change the effect's level. Note that it is a 0-based index, so for level 1 you type 0, for level 2 you type 1, and so on. Example:

/effect @a[lm=10,l=20] speed 1 1

to give the players speed II.

If you don't want the particles to show up simply add true to the end of the command:

/effect @a[lm=10,l=20] speed 1 0 true

How it Works

The @a[lm=10,l=20] is the part that does the magic. That is where you select who you want the effect to be applied to. The @a selects all online players, and the part in []s lets you narrow down your search.

[l=20] sets the maximum amount to target. [lm=10] sets the minimum. This means that anyone with a minimum of 10 levels and a maximum of 20 levels will be targeted.

The command only gives the effect for one second. But because the command block repeats every 20 times a second, it will keep giving the effect preventing it from running out.


If you want the effect to only be applied once for a certain time, it will be a bit harder. Please comment below if you would like that.