How can I give a effect to someone who spawned a bat?
I am making a murder mini-game and I wanted to make it so that when you right click with a sword you get speed boost, but that did not work so I tried making it that when they spawn in a bat, the bat dies and it gives only the player who spawned in the bat speed boost.
If this could be made much easier, I would gladly use that way.
The best way to see if someone used an item (in your case a spawn egg) is with scoreboards. From the quality of your question I'm going to assume you don't know what your doing.
First you're going to have to make the scoreboard
/scoreboard objectives add <score_name> stat.useItem.minecraft.spawn_egg
note: <score_name>
can be anything you want, it just can't have any spaces, and its best to avoid long and confusing names, but keep it long enough so it makes sense. Also this will trigger on any spawn egg, just a warning.
Then once you've set up your scoreboard you can use it to check for people who've used the spawn egg, with a selector like this: @a[score_<score_name>_min=1,score_<score_name>=1]
Which can be used in any command that requires an entity selector, such as
/effect @a[score_<score_name>_min=1,score_<score_name>=1] minecraft:speed <time> <amplifier>
notes: <time>
is how long the effect will last in seconds. <amplifier>
is how strong it will be, plus one, aka 0 is speed I, 1 is speed II etc.
For you, you'll probably want to put that command into a repeating command block. Just make sure to clear the score after, or the person who used the spawn egg will get the effect re-applied every tick. To clear the score from everyone, since it doesn't matter who's score gets reset, something like this can be used:
/scoreboard players set @a <score_name> 0
As with the other commands <score_name>
just has to be the same as when you made the scoreboard objective.
Hopefully your minigame works out, and for some advice, look into conditional command blocks, structure blocks, and scoreboards. All of them are extremely powerful when used right. Just start with scoreboards, they're the best.