Scoreboard for who flips a lever
I have a system where flipping a lever in a room will teleport the player, but I need a scoreboard to test who's actually flipped a lever to run the commands on. If the triggered commands after it only affected '@p' then the person standing closest to the lever would be affected even if they weren't the one who activated it. I tried to use a scoreboard for minecraft.use:minecraft.lever, but that's only for placing levers, not actually activating them. I need some other way to detect which player actually activated the lever.
You don't need a scoreboard in order to actually do it.
1. Place the lever on a block.
2. Place a command block under or behind that block.
3. Set the command to /tp @p <destination>
Personally, I'd use a button, so that you can just press the button and not have to worry about the next person who comes into the room, but it's up to you. Of course, there is the off-chance that someone will be in front of you when you press the lever or button, but if that ever happens, you can just press the button again.
Unfortunately, /tp @a[scores={lever=1..}] <destination>
will not work because there are no criteria for flipping a lever or pushing a button, which means that in order to make it work you'd have to do /scoreboard players add @p lever 1
and /tp @a[scores={lever=1..}] <destination>
, but then it's the exact same as the /tp @p
command and is ultimately just more complex and is not needed.
Edit: The only problem is that the closest person will be teleported even if they didn't flip the lever, however, there is no workaround for that. You'll just have to make sure that the second room is at least 4 blocks away, and hope that no one is standing closer to the lever than the person who flips it.