Randomizer Help

Hello, I can’t seem to figure out why my random face script (server script) won’t work. It’s only picking the first face, when it should pick outta the 5 faces

Module:

local Beginning = "http://www.roblox.com/asset/?id="

return {
	GirlFaces = {{
		Beginning.."144080495",--smile
		Beginning.."494290547",
		Beginning.."209713952",
		Beginning.."83022608",
		Beginning.."12145059"
	}},
	BoyFaces = {{
		Beginning.."144080495",--smile
		Beginning.."110287880",
		Beginning.."83017053",
		Beginning.."20722053",
		Beginning.."209715003"
	}}
}

Server Script:

local Face = ""

if ChosenNPC.NPCGender == "Girl" then
     Face = table.unpack(NPCFacesModule.GirlFaces[math.random(1, #NPCFacesModule.GirlFaces)])
     print(Face)
elseif ChosenNPC.NPCGender == "Boy" then
     Face = table.unpack(NPCFacesModule.BoyFaces[math.random(1, #NPCFacesModule.BoyFaces)])
     print(Face)
end

NewNPC.Head.Face.Texture = tostring(Face)
Face = ""

What Face prints:
image

1 Like

why do you have a table within a table?
i think that might be part of the reason why it’s not working

edit: i removed the unpack and the double table and it works. cleaned up your code a little too

local Beginning = "http://www.roblox.com/asset/?id="

return {
	Girl = {
		Beginning.."144080495",
		Beginning.."494290547",
		Beginning.."209713952",
		Beginning.."83022608",
		Beginning.."12145059"
	},
	Boy = {
		Beginning.."144080495",
		Beginning.."110287880",
		Beginning.."83017053",
		Beginning.."20722053",
		Beginning.."209715003"
	}
}
local Face
local Gender = ChosenNPC.NPCGender

Face = NPCFacesModule[Gender][math.random(1, #NPCFacesModule[Gender])]
print(Face)

NewNPC.Head.Face.Texture = tostring(Face)
Face = ""
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.