Hello! I have been writing a simple little startup function for my enemy NPC's. Everything is going great until I want to populate the "name tag" that I have made for it. Code Below...
local ServerStorage = game:GetService("ServerStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local EnemyStats = require(ServerScriptService:WaitForChild("EnemyStats"))
local StartUpFunctions = {}
function StartUpFunctions.NPCStatLoader()
local BattleField = game.Workspace:GetChildren()
for i,Enemy in pairs(BattleField) do
if Enemy:FindFirstChild("Humanoid") then
for Type,Value in pairs(EnemyStats) do
if Enemy.Name == Value.Name then
local Humanoid = Enemy:FindFirstChild("Humanoid")
Humanoid.MaxHealth = Value.Health
Humanoid.Health = Value.Health
local OverHeadGUI = Enemy:FindFirstChild("OverHeadGUI")
OverHeadGUI:FindFirstChild("HealthBar").Text = Value.Health.. " / " ..Value.Health
OverHeadGUI.NameLabel.Text = Value.Name
if Value.Weapon ~= nil then
local WeaponsList = ServerStorage:FindFirstChild("Weapons"):GetChildren()
for Index,Weapons in pairs(WeaponsList) do
if Weapons.Name == Value.Weapon then
local ClonedWeapon = Weapons:Clone()
ClonedWeapon.Parent = Enemy
end
end
end
end
end
end
end
end
return StartUpFunctions
The issue comes in line 17 with the output giving the error of "attempt to index nil with 'FindFirstChild'. The path of children/parent are the model (enemy) to BillboardGUI to TextLabel. The odd thing also is that if I load up the world, it does auto populate it properly by giving the proper name and health values.
If you have any idea why this error is being thrown, I would greatly appreciate hearing it because it says it cant index it, but It is indexing it.
Thank You
