RPG enemy Scripts?

Ok, I hate to have to make this a Topic but I’m just not finding any answers anywhere. I am currently Working on an RPG and have no clue what to do with my Enemies. Like should I have each enemy have their own script or what is the real way to go about this? I don’t know what I even need to do to make the enemies work right in the first place. I’ve looked all over the Devforum and no luck so far. All the Youtube tutorials want you to base it off of someone else’s work. Like Chrythm’s RPG kit or whatever. That doesnt work for me. I’m trying to LEARN how to do this myself. I’m not asking anybody to make any scripts for me, just for somebody to at least tell me what the goal is, or where I can learn up on it. Like should I have Multiple scripts per enemy, 1 for Following the player, 1 for Exp/Gold, 1 for weapon drops, etc. I’m just trying to wrap my head around what I should be trying to do with the enemies. Thank you for taking the time to read this!

You should have 1 script which controls all the enemies, if each enemy has its own or multiple own scripts, having lots of enemies can lag much more.

Modules would be a good way to handle this, with functions for spawning, moving, etc.

4 Likes

A loop could be done. For example, if you had rigged enemies and you put them in a folder, you could loop through them to make them all move toward the player once in a certain distance. For example:

while wait() do
        for i, v in ipairs(MyFolder) do
               --Pathfinding script
        end
end

CollectionService is a good way to control all of your AIs at once and seperating the scripts for following, gold, drops and etc maybe could just be wrapped into 1 module script and have the main script use the module script

If you need help with the script then I recommend YellowMustang’s video about AI and can show you the basics of making the AI

3 Likes

Thank you! This video is a LOT of help to point me in the right direction!

Hey, sorry to reply again when it’s a few days later but I’m having some issues. I’ve watched the video a few days ago and copied his example as he went along to try it out and see how it worked, then figure out how to implement it into my game. There’s just one catch. It didn’t work! I’ve never used coroutines before and I’m used to at least having an error code to tell me where everything went wrong. I know that I must have messed something up, but I just can’t figure out what. So I’m trying to study up on coroutines and I found that coroutine.resume() can also submit an error but I’m not really quite understanding the right way to go about this.

In the video he uses Coroutine to make a new thread so essentially

task.spawn(function()
-- Do something
)

and

local coro = coroutine.wrap(function()
--do something
)
coro()

will also work
I would use task.spawn() if I were you
if you see a error then it’ll be easier to see probably
if you want to understand coroutines then go to somewhere else as I’m not too familiar with it either

1 Like

Okie Dokie! Thank you for your help!