how do i make sure that a player is in the correct gamemode on entering any dimension through death

i made a custom adventure dimension in fabric 1.21.6 the warp pads that send people to and from the dimension work correctly to assign them a game mode before sending them.

what i don't have is a check for when a player dies in the adventure dimension, or otherwise teleports home.

what i tried was a datapack that would run a function when a player enters the overworld. but when i killed myself in creative mode, entering the overworld did not trigger it.

i should want to know how to set a player's gamemode when they enter any vanilla dimension or my custom ones. i didn't want one that ran every tick, as it would be annoying and laggy and wouldn't differentiate between me being in creative to make structures and me being a player. i'm ok with setting my gamemode after entering a dimension to do work stuff.

how do i make sure that a player is in the appropriate gamemode on entering a dimension, or at death? i'm also ok with using death to reset game modes.

attached is the datapack that failed to register a teleportation by death.

Continue to help post