Ive tried swicthing the if statement around and changing a few things but i still get the same issue where when i place my tower down itll multiply the gold earned by the amount of that tower placed. For example i place 4 farms down i earned 400 per attack but if i have 1 placed i earn 100 per attack. also having a issue where the support towers still try to aim towards the direction itd be attacking
Heres my attack function
function tower.Attack(newTower, player)
local config = newTower.Config
local target = tower.FindTarget(newTower, config.Range.Value, config.TargetMode.Value)
if target and target:FindFirstChild("Humanoid") and target.Humanoid.Health > 0 then
local targetCFrame = CFrame.lookAt(newTower.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
newTower.HumanoidRootPart.BodyGyro.CFrame = targetCFrame
local damage = config.BaseDamage.Value --the base damage of the tower
print(damage)
for i, buffval in pairs(config.Damage:GetChildren()) do--affecting buffs
local buff = buffval.Value --will lead to the tower's buff
if buff.Parent then
local tower = buff.Parent.Parent.Parent
if not tower or not tower.Parent then
buffval:Destroy()
else
local newpos = newTower.HumanoidRootPart.CFrame.Position
local pos = tower.HumanoidRootPart.CFrame.Position
local range = buff.Parent.Parent.Range.Value
if (pos-newpos).Magnitude > range then --towers can move maybe?
buffval:Destroy()
end
end
else
buffval:Destroy()
end
end
for i,tower in pairs(workspace.Towers:GetChildren()) do-- just gonna call it towerfolder
--have some check to determine if it's a support such as this
if tower.Config.Type.Value == "Farm" then
local PointsValue = 100
player.Gold.Value += PointsValue
elseif tower.Config.Type.Value == "Support" then --having a type config can be very useful
local bufftype = tower.Config.BuffType.Value --the type of buff?(only works if has one buff)
local buff = tower.Config.Buff.Value --how much it buffs (only works if has one buff)
local range = tower.Config.Range.Value -- the range of the buff
if bufftype == "Damage" and (newTower.HumanoidRootPart.CFrame.Position-tower.HumanoidRootPart.CFrame.Position).Magnitude <= range then
print("Applying buff")
damage *= 1+buff --assuming the buff is 0.10 if +10%, etc
local newbuff = Instance.new("ObjectValue")
newbuff.Name = "Buff"
newbuff.Value = tower.Config.Buff
newbuff.Parent = tower.Config.Damage
end
end
end
print(damage)
animateTowerEvent:FireAllClients(newTower, "Attack")
target.Humanoid:TakeDamage(damage)
config.Damage.Value = damage
if target.Humanoid.Health <= 0 then
player.Gold.Value += target.Humanoid.MaxHealth
player.Kills.Value += 1
end
task.wait(config.Cooldown.Value)
end
task.wait(0.1)
if newTower and newTower.Parent then
tower.Attack(newTower, player)
end
end
What im trying to achieve is where when i place the farm itll award the player gold every time the cooldown finishes. And would like it where my support towers or farm tower dont run the attack animation and dont try to aim towards the enemy. Dont expect any code to written out. Im pretty sure i missused something somewhere