As a GM, you should have a sheet with the stats for your PCs that determine these kinds of rolls. If the PC wouldn't know if they succeed or fail, then the player shouldn't know the result of the roll, or sometimes even what the roll is for in the first place.
It's hard to avoid metagaming when you very clearly failed a roll and the GM says "Everything seems fine and normal to you"
I mostly disagree. It takes away a feeling of agency even if its still random at the end of the day. Just trust your players not to meta game. There are exceptions when it would be hard for the player to still get the intended experience when not meta gaming; but leaving the existence of that experience up to a roll in the first place is probably whats at fault.
Perception stats exist for a reason, and I'd argue they're usually incompatible with knowing the result of the roll, even with players who try not to meta-game. Even if they behave, they're subconsciously going to know how they rolled and that will change the experience, unless you start meta-meta-gaming (changing the success window, frequently calling for rolls for nothing, etc.). Personally that seems like a pound of cure vs an ounce of prevention.
If a semi-spoiler-laden, actively counter-meta-gamed experience is what your group likes, more power to you. But more often than not, I think the GM rolling for checks where success/failure isn't obvious preserves the experience for all players and prevents meta-gaming, both intentional and subconscious.
Yeah, I love rolling dice, but certain rolls shouldn't be done by the players.
Rolling on a hit in combat? That should definitely be the player. You know how well you swing your sword and when it makes good contact.
Rolling on perception should almost always be done by the DM. This is especially true when another party member can rescue the bad roll. Like, someone rolls to spot a hidden enemy. They fail, but shouldn't know it, but they rolled a 2, so... Another player at the table sees this horrible roll and they have their character light a torch and look out into the wilderness. Sure, that's metagaming, but it's really hard to avoid when you know someone failed a potentially important roll.
One idea I'd like to see, and might try if I ever DM'd a game would be Dunning-Kruger rolls. The Dunning-Kruger effect is basically how people who are incompetent at something sometimes think they're much better than they are, and people who are experts (and realize how complex things are) underestimate their own competence.
So, in this case, the DM rolls a die which says whether the rolls are normal or reversed, then the player rolls. If the DM's roll said the player's roll was reversed, the player's 20 might become a 1, or a 1 might become a 20 (the actual number is 21 - roll). Mid rolls stay roughly the same: a 10 becomes an 11, for example.
If the barbarian is trying to check for traps and gets an 18, the DM might say "You're confident there are no traps", but that could be the result of overconfidence when they really "rolled" a 3. If they get a 10, the DM might say "You didn't notice a trap, but you're not sure". You could set this up so if someone has a proficiency, the DM rolls a D10 and only a 1 means the player's role is reversed. But, if the player is trying something they're not good at, a 1 to 5 on the D10 means it's reversed.
I haven't tried this, so there may be serious flaws in it in reality. But, I like the idea of players still being able to roll for something like spotting a hidden enemy, but not knowing for sure if their roll is good or not.
If a player metagamed like that at my table, I'd punish them by not having any monster appear until everyone is back in bed. And have the character on watch be surprised.
The first (and pretty much only) time I played D&D I didn't know what "metagaming" was and accidentally thought about the puzzle as myself instead of as my player. Apparently the DM wanted justice and I ended up ruining the session for everyone. Needless to say I didn't go back out of guilt
Moral of the story: please try to be patient with your players. Not all of us are great at avoiding metagaming immediately :\
The way that my groups play it, the party is basically a hivemind of everything that the RL players know (minus Bestiary minutiae the PCs would have zero reason to know on first encounters), plus any knowledge the PCs might get from dice rolls. Just because I'm playing the 8 Int barbarian doesn't mean I have to go sit in the corner waiting for the next roll for initiative.
We just handwave the solution as saying the smartest PC came up with the plan, or if a dumb character rolls high, we role play him catching the Smart Ball and have the other PCs react in character.
Different tables have different tolerances for metagaming. Sorry you had a table that would rather browbeat the new guy for pushing that boundary instead of giving you a chance to adjust.
That's kinda dumb... It leads into why I don't really like "puzzles" in the traditional sense in TTRPGs... Either it is simply a DC you have to beat in a roll, and that is it, or it requires the player (not the character) to be good at solving puzzles. Otherwise, it isn't a puzzle, it is just an atypical "lock" requiring an atypical "key" reminiscent of old point-and-click adventure games where you just can't proceed until you find the McGuffin (some random detail or piece of information that is hidden away that in turn "solves" the puzzle that you could not have hoped to solve without it).
I'd love to be proven wrong, but I definitely haven't seen it done well.
Maybe I'm weird but I like it when my party meta-games like this since then I get to mess with them. They never really know what I'm going to do. If they interrupt the long rest they have a con save for a lvl of exhastion (DC 12+ based on the number of times I've asked them to roll) no matter what, but the missed perception check does always mean something happened. Once it was a Brownie taking 2 copper and a ration from every player while granting them advantage on every skill check until the next long rest, another was a group of Pixies stealing all of their pants (equiped and unequiped) and hanging them from a tree two days journey away. Ambushes are pretty rare at my table but something happens just about every night.
I love using Fey for this cause if they get bored they love making mortals miserable.