One way of playing traps in games is to have them hidden from the players and rely on things like character Perception rolls or Passive Perception skill to notice them. This is the mode encouraged by the 5th Edition Dungeons & Dragons rules.
This approach means that sometimes characters may fail to notice traps, and the players will blunder their characters into them. While this produces the occasional "took damage from a trap" effect that is part of the genre, it can be a feel-bad for players, who have no chance to react or make any decisions about it. Another effect is that usually the DM doesn't want to telegraph a trap that may be hidden by calling for players to roll against Perception, so they handle it mechanically by using Passive Perception - which essentially means that it's always the same characters (with the highest Perception scores) who spot everything. This can get a little boring and predictable.
Another approach, encouraged by the Old School Revival gaming movement is to treat traps more as puzzles. Rather than walk down a corridor and have some fixed chance (based on Perception skills) of blundering into a pit trap, the DM will simply tell the players that they notice something odd.
"The floor ahead of you seems to be sagging slightly, and the colour of the flagstones is slightly different."
Now, the players have been fairly warned. If they walk ahead without caution, they step on the loose floor and fall into the pit. But they probably won't do that. They'll slow down and take a look. They might poke the floor. Now the DM can reveal that it's a pit trap, and they estimate the weight of two people is likely to collapse the floor. So now the heroes have a puzzle. How do they get to the other side? Do they risk going one at a time? Do they try to walk around the narrow edge? Do they use magic? Do they try something else creative? What if goblins now appear from behind them?
The trap has turned from something that randomly hurts people without warning, into an obstacle that requires the players to think to get past, or to re-evaluate how badly they want to go in this direction. Maybe they should go back and find another path. It gets rid of the random damage feel-bad nature of traps in games and turns them into interesting problems to be solved.
If you play 5th Edition, consider getting rid of Perception as a skill altogether, and using this approach for hidden things instead. It's not going to suit everyone's preferred play style, but it may suit yours.
(It also works for clues. If you have clues to something mysterious, just let them find the clues and then they can get to the fun bit of solving the mystery, rather than having the clues hidden behind Perception rolls that they may fail, leading to the frustrating situation where you to have to figure out some other way for them to get the information they need to solve the mystery.)
Commentary by memnarch (who has not seen the movie)
Aha! Feeling the midi-chlorians inside the leaf; I was right! ... Which probably means that it's not like this in the movie. Or at least, not a specific leaf from that tree. The "feel the Force" part could work at least. Or, something I just thought of, this could have been testing Rey's reflexes! If she had used the Force, she would have been able to grab the leaf before getting her hand whacked!
Luke is really pulling off the "half crazed mentor" look. Bug-eyed face, surprised/interested expression, wild semi-unkempt hair, and just tossing the leaf away after simply hitting Rey with it. Just like the lightsaber near the start of the movie. If this was solely the comic, I'd be confused at why Corey was tossing away a special leaf like that, but it's more likely just a random leaf. Now I'm just thinking Luke's gotten in the habit of tossing things away he doesn't want anymore. And if they're friendly enough, the Porg Fish people probably just pick up the stuff for him anyway.
Transcript
Luke: Concentrate! What do you feel?
Rey: Like... a leaf?
Luke: I whack her hand with the leaf.
[SFX]: Thwap!
Rey: Ow!!
Rey: What was that about?
Luke: The leaf is full of midi-chlorians. One of the few that the old tree sprouts occasionally.
Luke: The Force isn’t something the GM telegraphs. You have to look for it when it’s not obvious!
Luke: Once you find it, you can manipulate it. Use it.
[SFX]: toss {Luke tosses the leaf away}
Rey: So it’s like advancing down a corridor, poking the ceiling with a 10-foot pole. Find the trap, then spring it on the monster.
Luke: Right!
Rey: Only one time I did that and rocks fell and everyone died.
GM: That was a great night.