I decided to use Region3’s for detecting when a zombie is inside of my range area.
local Experience = game
function CreateRegion3FromPart(Part)
return Region3.new(Part.Position-(Part.Size/2),Part.Position+(Part.Size/2))
end
function GetEnemysInPart(Part)
local Region = CreateRegion3FromPart(Part)
local PartsInRegion = Experience:GetService("Workspace"):FindPartsInRegion3(Region,nil,math.huge)
for _, Part in pairs(PartsInRegion) do
local Enemy = Part.Parent:FindFirstChildOfClass("Humanoid")
if Enemy then
if Enemy:GetAttribute("IsZombie") then
print("Enemy Found!".. Enemy.Name) -- Will work from here later.
break
end
end
end
end
while task.wait(0.5) do
GetEnemysInPart(script.Parent:WaitForChild("TowerRange"))
end
Is there anything to change to make sure it will always detect a zombie?
Thanks, WE.