Hey!
This is a system I made completely by myself, and usually I make some small issues. This is something I’m proud of, and was wondering if it can be improved.
Thanks!
--This is a module btw
local TowerModule = {}
function TowerModule.SingleAttack(TowerModel)
coroutine.wrap(function()
local MainPart = TowerModel.MainPart
local CurrentLevel = TowerModel.CurrentLevel
local Levels = TowerModel.Levels
local CurrentLevel = Levels[CurrentLevel.Value]
local TargetMode = CurrentLevel.TargetMode
local Target = TowerModel.CurrentTarget
local Map = game:GetService("ReplicatedStorage").SelectedMap
if TargetMode.Value == 1 then
for index, zombie in pairs(Map.Value.RunningZombies:GetChildren()) do
local HRP = zombie.HumanoidRootPart
local MagnitudeFromMainPart = (MainPart.Position - HRP.Position).Magnitude
local MagnitudeFromEndPoint = (HRP.Position - Map.Value.Path.EndPoint.Position).Magnitude
if Target.Value then
local CurrentMagnitudeFromMainPart = (MainPart.Position - Target.Value.HumanoidRootPart.Position).Magnitude
local CurrentMagnitudeFromEndPoint = (Target.Value.HumanoidRootPart.Position - Map.Value.Path.EndPoint.Position).Magnitude
if CurrentMagnitudeFromEndPoint > MagnitudeFromEndPoint then
Target.Value = zombie
end
elseif MagnitudeFromMainPart <= CurrentLevel.Range.Value then
Target.Value = zombie
end
end
if Target.Value then
Target.Value.Humanoid:TakeDamage(CurrentLevel.Damage.Value)
end
if Target.Value then
if Target.Value.Parent ~= workspace then
Target.Value = nil
else
warn(Target.Value.Name, "Is still in workspace!")
end
end
end
end)()
end
return TowerModule