Hello!
So im working on a small RPG system. The goal is to make a really easy way to add new enemys. All I would have to do is change how they look, and there stats like Health, Damage, etc, in a config folder I made in the enemy. The only problem is if I spawn more than 1 it just seems to break. No errors though.
Inside the NPC there is this script.
--// Variables
local enemy = script.Parent
local humanoid = enemy:WaitForChild("Humanoid")
local zoneAPI = require(game:GetService("ReplicatedStorage").APIs.Zone)
local zone = zoneAPI.new(script.Parent.ZONE) -- Zone is the hitbox
--// Variables
--// Stats Vars
local HEALTH = enemy.CONFIG.Health.Value
local DAMAGE_MIN = enemy.CONFIG.Damage.DamageMin.Value
local DAMAGE_MAX = enemy.CONFIG.Damage.DamageMax.Value
local SPEED = enemy.CONFIG.Speed.Value
local TARGET = enemy.CONFIG.TARGET.Value
--// Stats Vars
--// Load Character Stats
humanoid.Health = HEALTH
humanoid.WalkSpeed = SPEED
--// Load Character Stats
zone.playerEntered:Connect(function(player)
TARGET = player
print(player)
end)
zone.playerExited:Connect(function(player)
if TARGET == player then
TARGET = ""
end
print(player)
end)
while wait(0.5) do
if TARGET ~= "" then
humanoid:MoveTo(TARGET.Character.HumanoidRootPart.Position)
end
if humanoid.Health == 0 then
wait(2)
enemy:Destroy()
end
end
And im using ZonePlus v3.2.0 | Construct dynamic zones and effectively determine players and parts within their boundaries for the NPC’s range hitbox.
The problem is the NPC does not chase the player when there is more than 1 NPC. The hitbox is a large sphere.
Video:
https://lowkey.gg/v/edf1db1e-19e8-4efd-b119-720d1bcc6588