-
What do you want to achieve? I tried to make a system where all enemies haves their stats by individual module that its named the enemy’s name, idk if you get it but here’s what i meant
-
What is the issue? I get the error
ServerScriptService.Main.Enemy:156: attempt to index nil with 'FindFirstChild'
and comes from this line:local enemyStats = require(enemyModuleAccess:FindFirstChild(name))
, and this is how i use it:enemy.Spawn("Moonling", 6 * enemyCountMultiplier, 1.5, map)
-
What solutions have you tried so far? I dont know how to fix this and theres no similar issue no mine i guess except this error
local currentGameMode = workspace.Info.CurrentGamemode
local enemyModuleFolder = ServerScriptService.EnemyModule
local enemyModuleAccess
if currentGameMode and currentGameMode.Value == "Easy" then
enemyModuleAccess = enemyModuleFolder.EasyMode
elseif currentGameMode and currentGameMode.Value == "Normal" then
enemyModuleAccess = enemyModuleFolder.NormalMode
elseif currentGameMode and currentGameMode.Value == "Hard" then
enemyModuleAccess = enemyModuleFolder.HardMode
end
function enemy.Spawn(name, quantity, interval, map)
for i = 1, quantity do
local enemyStats = require(enemyModuleAccess:FindFirstChild(name))
task.wait(interval)
local enemyExists
if currentGameMode and currentGameMode.Value == "Easy" then
enemyExists = ServerStorage.Enemies.EasyMode:FindFirstChild(name)
elseif currentGameMode and currentGameMode.Value == "Normal" then
enemyExists = ServerStorage.Enemies.NormalMode:FindFirstChild(name)
elseif currentGameMode and currentGameMode.Value == "Hard" then
enemyExists = ServerStorage.Enemies.HardMode:FindFirstChild(name)
end
if enemyExists then
local newEnemy = enemyExists:Clone()
newEnemy.PrimaryPart.CFrame = map.Start.CFrame
newEnemy.Parent = workspace.Enemies
enemy.Optimize(newEnemy)
local movingTo = Instance.new("IntValue")
movingTo.Name = "MovingTo"
movingTo.Value = 1
movingTo.Parent = newEnemy.Config
for i, object in ipairs(newEnemy:GetDescendants()) do
if object:IsA("BasePart") or object:IsA("MeshPart") then
object.CollisionGroup = "Enemy"
end
end
local health = enemyStats["Health"]
newEnemy:SetAttribute("Health", health)
newEnemy:GetAttributeChangedSignal("Health"):Connect(function()
if newEnemy:GetAttribute("Health") <= 0 then
enemy.Die(newEnemy)
end
end)
coroutine.wrap(enemy.Move)(newEnemy, map)
end
end
end