Hello, _Tarna_ Its gamerule not gamemode, Gamemode switches the gamemode of the target in the next string of the command, gamerule changes the game rules like if you want to keep your inventory or not, change how fast crops grow, etc... So the correct answer is /gamerule keepInventory true.