diff --git a/src/lua_baselib.c b/src/lua_baselib.c
index bbcec06d3a8c01e5a8975fc769381f31b5f04c7b..e6ab7a7e1c63734eb1c63344e28916b79f75238c 100644
--- a/src/lua_baselib.c
+++ b/src/lua_baselib.c
@@ -309,6 +309,19 @@ static int lib_pRemoveMobj(lua_State *L)
 	return 0;
 }
 
+// P_IsValidSprite2 technically doesn't exist, and probably never should... but too much would need to be exposed to allow this to be checked by other methods.
+
+static int lib_pIsValidSprite2(lua_State *L)
+{
+	mobj_t *mobj = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
+	UINT8 spr2 = (UINT8)luaL_checkinteger(L, 2);
+	//HUDSAFE
+	if (!mobj)
+		return LUA_ErrInvalid(L, "mobj_t");
+	lua_pushboolean(L, (mobj->skin && (((skin_t *)mobj->skin)->sprites[spr2].numframes > 0)));
+	return 1;
+}
+
 static int lib_pSpawnMissile(lua_State *L)
 {
 	mobj_t *source = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ));
@@ -2005,6 +2018,7 @@ static luaL_Reg lib[] = {
 	// don't add P_SetMobjState or P_SetPlayerMobjState, use "mobj.state = S_NEWSTATE" instead.
 	{"P_SpawnMobj",lib_pSpawnMobj},
 	{"P_RemoveMobj",lib_pRemoveMobj},
+	{"P_IsValidSprite2", lib_pIsValidSprite2},
 	{"P_SpawnMissile",lib_pSpawnMissile},
 	{"P_SpawnXYZMissile",lib_pSpawnXYZMissile},
 	{"P_SpawnPointMissile",lib_pSpawnPointMissile},
diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c
index 58c1b14f2032a3c364f51353fc33db4769cf15c9..9ebc38a61123b756a0085b0730df8836ca9ca3fd 100644
--- a/src/lua_mobjlib.c
+++ b/src/lua_mobjlib.c
@@ -417,7 +417,7 @@ static int mobj_set(lua_State *L)
 		mo->frame = (UINT32)luaL_checkinteger(L, 3);
 		break;
 	case mobj_sprite2:
-		mo->sprite2 = (UINT8)luaL_checkinteger(L, 3);
+		mo->sprite2 = P_GetMobjSprite2(mo, (UINT8)luaL_checkinteger(L, 3));
 		break;
 	case mobj_anim_duration:
 		mo->anim_duration = (UINT16)luaL_checkinteger(L, 3);
diff --git a/src/p_local.h b/src/p_local.h
index de717801e7611f66a8f2764c566774f50bffc2ce..ee1aacb4f17440000479e6be4c534806071261e7 100644
--- a/src/p_local.h
+++ b/src/p_local.h
@@ -211,6 +211,7 @@ void P_PrecipitationEffects(void);
 void P_RemoveMobj(mobj_t *th);
 boolean P_MobjWasRemoved(mobj_t *th);
 void P_RemoveSavegameMobj(mobj_t *th);
+UINT8 P_GetMobjSprite2(mobj_t *mobj, UINT8 spr2);
 boolean P_SetPlayerMobjState(mobj_t *mobj, statenum_t state);
 boolean P_SetMobjState(mobj_t *mobj, statenum_t state);
 void P_RunShields(void);
diff --git a/src/p_mobj.c b/src/p_mobj.c
index 82a923279bf0afdf7e7ccb7b1c4488adeba9b277..669f8cd1f829a985338ca67abb7693b85ca96393 100644
--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -189,17 +189,16 @@ static void P_CyclePlayerMobjState(mobj_t *mobj)
 // P_GetMobjSprite2
 //
 
-static UINT8 P_GetMobjSprite2(mobj_t *mobj, UINT8 spr2)
+UINT8 P_GetMobjSprite2(mobj_t *mobj, UINT8 spr2)
 {
 	player_t *player = mobj->player;
 	skin_t *skin = ((skin_t *)mobj->skin);
 	boolean noalt = false;
-	UINT8 numframes;
 
 	if (!skin)
 		return 0;
 
-	while (((numframes = skin->sprites[spr2].numframes) <= 0)
+	while ((skin->sprites[spr2].numframes <= 0)
 		&& spr2 != SPR2_STND)
 	{
 		switch(spr2)