Here is the enemy script local enemy = script.Parent
local humanoid = enemy:WaitForChild("Humanoid")
local attackRange = 1000
local attackRate = 1
local damage = 10
local target = workspace:WaitForChild("TowerModel")
local function moveToTarget()
humanoid:MoveTo(target.Position)
end
local function isInAttackRange()
local distance = (enemy.HumanoidRootPart.Position - target.Position).Magnitude
return distance <= attackRange
end
local function attackTarget()
if target:FindFirstChild("Humanoid") then
target.Humanoid:TakeDamage(damage)
end
end
while true do
if target then
if isInAttackRange() then
attackTarget()
else
moveToTarget()
end
end
wait(attackRate)
end