I'm making a tds game and i experienced an error.
I tried using :WaitForChild() but it gave me the same exact error.
function towerModule.attackMob(newTower, player) local config = newTower.Config local target = findNearestTarget(newTower, config.Range.Value) if target and target:FindFirstChild('Zombie') and target.Zombie.Health > 0 then local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position) newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame target.Zombie:TakeDamage(config.Damage.Value) if target.Zombie.Health <= 0 then player.Gold.Value += target.Zombie.MaxHealth end task.wait(config.Cooldown.Value) end task.wait(0.1) towerModule.attackMob(newTower) end
I believe the code block is the reason why it's erroring.
But, here is the error that i am experiencing:
14:56:44.149 ServerScriptService../main../tower:32: attempt to index nil with 'Gold' - Server - ./tower:32 14:56:44.149 Stack Begin - Studio 14:56:44.149 Script 'ServerScriptService../main../tower', Line 32 - function attackMob - Studio - ./tower:32 14:56:44.149 ? Script 'ServerScriptService../main../tower', Line 38 - function attackMob (x49) - Studio - ./tower:38 14:56:44.152 Stack End
I would be very happy for solutions.
Change the line 16 from this:
towerModule.attackMob(newTower)
To this:
towerModule.attackMob(newTower, player)