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.

7 comments
The line that's causing the error is if target.Zombie.Health <= 0 then player.Gold.Value += target.Zombie.MaxHealth
Are you sure “Gold” is REALLY inside player? Maybe it’s in the leaderstats. Try player.leaderstats.Gold.Value
It's in player.
Ok.
In using module.attactMob(), did you put the player in the second argument or left it nil?
cuz you might've forgot
I did put the second argument.