diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c
index 33cc1b36729cb16bb0189133b8d1e3cdcf227827..ed4ca4e48bc357668ab2893d0e0940f06d07e574 100644
--- a/src/lua_hudlib.c
+++ b/src/lua_hudlib.c
@@ -497,7 +497,7 @@ static int libd_getColormap(lua_State *L)
 	{
 		skinnum = (INT32)luaL_checkinteger(L, 1);
 		if (skinnum < TC_ALLWHITE || skinnum >= MAXSKINS)
-			return luaL_error(L, "argument #1 is out of range");
+			return luaL_error(L, "skin number %d is out of range (%d - %d)", skinnum, TC_ALLWHITE, MAXSKINS-1);
 	}
 	else // skin name
 	{
diff --git a/src/lua_mathlib.c b/src/lua_mathlib.c
index b98c515297aceafff397625ed60f5b1e43676cfb..c1e13db9f91bdb74881662124f47560719065875 100644
--- a/src/lua_mathlib.c
+++ b/src/lua_mathlib.c
@@ -188,7 +188,9 @@ static int lib_all7emeralds(lua_State *L)
 // Returns both color and frame numbers!
 static int lib_coloropposite(lua_State *L)
 {
-	int colornum = ((int)luaL_checkinteger(L, 1)) % MAXSKINCOLORS;
+	UINT8 colornum = (UINT8)luaL_checkinteger(L, 1);
+	if (colornum >= MAXSKINCOLORS)
+		return luaL_error(L, "skincolor %d out of range (0 - %d).", colornum, MAXSKINCOLORS-1);
 	lua_pushinteger(L, Color_Opposite[colornum*2]); // push color
 	lua_pushinteger(L, Color_Opposite[colornum*2+1]); // push frame
 	return 2;
diff --git a/src/lua_mobjlib.c b/src/lua_mobjlib.c
index bf4ee0b286d11ef9310fd2a5fe1c3365adde2597..7e1fe578eaef8065673b569025800c37f9dc55da 100644
--- a/src/lua_mobjlib.c
+++ b/src/lua_mobjlib.c
@@ -509,8 +509,13 @@ static int mobj_set(lua_State *L)
 		return luaL_error(L, "mobj.skin '%s' not found!", skin);
 	}
 	case mobj_color:
-		mo->color = ((UINT8)luaL_checkinteger(L, 3)) % MAXTRANSLATIONS;
+	{
+		UINT8 newcolor = (UINT8)luaL_checkinteger(L,3);
+		if (newcolor >= MAXTRANSLATIONS)
+			return luaL_error(L, "mobj.color %d out of range (0 - %d).", newcolor, MAXTRANSLATIONS-1);
+		mo->color = newcolor;
 		break;
+	}
 	case mobj_bnext:
 		return NOSETPOS;
 	case mobj_bprev:
@@ -524,8 +529,8 @@ static int mobj_set(lua_State *L)
 	case mobj_type: // yeah sure, we'll let you change the mobj's type.
 	{
 		mobjtype_t newtype = luaL_checkinteger(L, 3);
-		if (newtype > MT_LASTFREESLOT)
-			return luaL_error(L, "mobj.type %u is out of bounds.", newtype);
+		if (newtype >= NUMMOBJTYPES)
+			return luaL_error(L, "mobj.type %d out of range (0 - %d).", newtype, NUMMOBJTYPES-1);
 		mo->type = newtype;
 		mo->info = &mobjinfo[newtype];
 		P_SetScale(mo, mo->scale);
diff --git a/src/lua_playerlib.c b/src/lua_playerlib.c
index 388fe3175f52ce09e5effddf7eb81b6fbdfc84e9..5d5fe5aad9809b6f417be2327431cb8fcc7d3389 100644
--- a/src/lua_playerlib.c
+++ b/src/lua_playerlib.c
@@ -389,7 +389,12 @@ static int player_set(lua_State *L)
 	else if (fastcmp(field,"flashpal"))
 		plr->flashpal = (UINT16)luaL_checkinteger(L, 3);
 	else if (fastcmp(field,"skincolor"))
-		plr->skincolor = ((UINT8)luaL_checkinteger(L, 3)) % MAXSKINCOLORS;
+	{
+		UINT8 newcolor = (UINT8)luaL_checkinteger(L,3);
+		if (newcolor >= MAXSKINCOLORS)
+			return luaL_error(L, "player.skincolor %d out of range (0 - %d).", newcolor, MAXSKINCOLORS-1);
+		plr->skincolor = newcolor;
+	}
 	else if (fastcmp(field,"score"))
 		plr->score = (UINT32)luaL_checkinteger(L, 3);
 	else if (fastcmp(field,"dashspeed"))