So, my tower script, has a reload function. if an enemy is in range after reloading, it errors out Attempt to index nil with 'Health'. any help?
for i, plrs in ipairs(game.Players:GetPlayers()) do
if target then
if target:FindFirstChild("Humanoid").Health < config.Damage.Value then --error here
plrs.leaderstats.Money.Value += target:FindFirstChild("Humanoid").Health
else
plrs.leaderstats.Money.Value += config.Damage.Value
end
end
end
for i, plrs in ipairs(game.Players:GetPlayers()) do
if target then
if target.Character:FindFirstChild("Humanoid").Health < config.Damage.Value then --error here
plrs.leaderstats.Money.Value += target.Character:FindFirstChild("Humanoid").Health
else
plrs.leaderstats.Money.Value += config.Damage.Value
end
end
end
for i, plrs in ipairs(game.Players:GetPlayers()) do
if target then
if target:FindFirstChildOfClass("Humanoid").Health < config.Damage.Value then --error here
plrs.leaderstats.Money.Value += target:FindFirstChildOfClass("Humanoid").Health
else
plrs.leaderstats.Money.Value += config.Damage.Value
end
end
end
If it doesn’t work, can you show me a screenshot of the children listed under your npc?