How to script AI

You saw the title. I won’t waste your time.

My game has buildings. When directed to the enemy’s (in this case, the AI’s) building, a noob will run to that building every 1 second and will take out one point per noob. Let’s just say the enemy building has 30 points; We need 30 noobs to attack, so it’d take 30 seconds.

I need to have the enemy (AI) be able to know when to attack back, and to know when to attack another building if it has less points (the lesser the points, the lesser amount of noobs it takes to destroy, hence, it is to conquer the building). The AI needs to be smart, and to react fast.

The issue is… I don’t know how to program, so I don’t know how to go about this.

I haven’t tried anything yet because I don’t know where to begin.

If anyone can help, please do! Thanks.

3 Likes

what does it need to do besides find the opposing building with the lowest points?
is this 1 npc sending 30 noobs to a building with 30 points? or is this 30 npcs working together to figure out if there are enough npcs already heading there or already working on it?

1 Like

The basic movement using AI would be Humanoid:Move(Vector3.new()) or Humanoid:MoveTo(workspace.part). If you want it to respond quickly, you calculate distance from parts etc. But since you say you can’t program it is practically impossible to create an NPC with no programming knowledge whatsoever.

You need to know the following to be able to start off with scripting an NPC-
Magnitude
Parts in a character
Calculating distance between a constantly moving part and another part.
Animations
Getting a player value with using the playerAdded function
Handling damage and values
Properties of humanoid
Accessing character rigs/parts.

Those are some of the essential things you need to start making an NPC, I’d recommend you watch videos on it. It will help you a lot.

Hope this helps.

1 Like

The first thing I would do is build my noob model. After that, I would make whatever the noob is going to come out of. To get the noob to spawn I would use :clone. Then I would use Roblox’s pathfinding service (Character Pathfinding) or SimplePath (SimplePath - Pathfinding Module) Then I would check if one of the noobs touched the AI building and remove 1 point of health. With this, though you might want to do a remote event so that way it syncs with the server overall just better if you are gonna use datastores or updating for all players.

Wouldn’t Roblox’s pathfinding do a better job at avoiding parts and calculating distance between multiple objects?

Roblox’s pathfinding requires complex calculations so it’s not very efficient unless you optimize it correctly.

The NPC (AI) owns a building, and it needs to be smart enough to attack the easiest building, and counter-attack when the player attacks it.

I’ve got the buildings, etc, I just need to figure out how to have the NPC (AI) attack on it’s own.


Thanks for the help.

EDIT: Take not that the Red is the NPC (AI), and the blue is the player who controls their buildings.

I have a programmer; However, he’s having some difficulties figuring out how to work the AI.

you could loop through a table of all available buildings and get the building with the lowest points
you could google “examples of getting min or max in unordered array” for examples

1 Like

Thank you. I’ll have to try that.