diff --git a/src/lua_baselib.c b/src/lua_baselib.c
index 1a62f39220f2ce05231d49a29d3da1f6cc5d5f4f..4666394edb603cc55449c9194513cf372f450726 100644
--- a/src/lua_baselib.c
+++ b/src/lua_baselib.c
@@ -1934,7 +1934,7 @@ static int lib_gSetCustomExitVars(lua_State *L)
 		if (lua_isnumber(L, 1) || n >= 2)
 		{
 			nextmapoverride = (INT16)luaL_checknumber(L, 1);
-			lua_pop(L, 1); // pop nextmapoverride; skipstats now 1 if available
+			lua_remove(L, 1); // remove nextmapoverride; skipstats now 1 if available
 		}
 		skipstats = lua_optboolean(L, 1);
 	}