ServerScriptService.Main.Tower:82: attempt to index nil with 'GetAttribute'
But I don’t get it?
function tower.Ability(newTower, target)
local Ability = newTower:GetAttribute("Ability")
if Ability and Ability == "AOE" then
local Primary = newTower.PrimaryPart
local Range = newTower:GetAttribute("AOERange")
local targets = GetNearestTargets(target.PrimaryPart, Range, workspace.Mobs)
if targets and #targets >= 1 then
for k, enemy in pairs(targets) do
enemy.Humanoid.Health -= newTower.Config.Damage.Value
end
end
end
end
As you can see I’m trying to make it so that my Tower has an AOE Attack Type, how do I fix this?
newTower is likely nil
Run this and see what the outcome is:
function tower.Ability(newTower, target)
if newTower == nil then warn("[!] newTower returned nil") return end
local Ability = newTower:GetAttribute("Ability")
if Ability and Ability == "AOE" then
local Primary = newTower.PrimaryPart
local Range = newTower:GetAttribute("AOERange")
local targets = GetNearestTargets(target.PrimaryPart, Range, workspace.Mobs)
if targets and #targets >= 1 then
for k, enemy in pairs(targets) do
enemy.Humanoid.Health -= newTower.Config.Damage.Value
end
end
end
end
function tower.Spawn(player, name, cframe, previous)
local allowedToSpawn = tower.CheckSpawn(player, name, previous)
if allowedToSpawn then
local newTower
local oldMode = nil
if previous then
oldMode = previous.Config.TargetMode.Value
previous:Destroy()
newTower = ReplicatedStorage.Towers.Upgrades[name]:Clone()
Yea, roblox removed that property on November 1st, as well as forcing it on. I still have to reperfect my animation system because of this. But let’s not talk about that.