Calling a Modulescript by a String Variable?
Hi! Sorry if this is too convoluted or doesn't make much sense, I am very new to scripting and haven't done it in a long time. I'm working on a modulescript that creates an NPC. Since NPCs can be of different types with a large number of different variables, it calls another modulescript while running based on what type of NPC it is asked to make, using the inputs CharID
to ensure all NPCs are unique, and template
to decide what NPC Template to grab. Telling it to make an NPC right now would look something like NPCProfiler:CreateCharacter(12345,"Human")
to make a Human character, as an example.
Here's an example of what I'm doing inside of "NPCProfiler" right now, with unrelated code removed.
1 | local Human = require(game.ServerScriptService.NPCTemplates.Human.HumanTemplate) |
2 | local Monster = require(game.ServerScriptService.NPCTemplates.Monster.MonsterTemplate) |
6 | function NPCProfiler:CreateCharacter(CharID,template) |
7 | template:GetTemplate(CharID) |
Basically, I need template:GetTemplate(CharID)
to match what the variable template is when CreateCharacter is run and then match with the list of modulescripts defined above (Human, Monster) so it can decide which one of those to run the function GetTemplate from since they all contain one, but this setup fails presumably because template is a string variable. This may be a really simple fix, and I just don't know it, so I'm hoping someone has some insight on a way to make this work.