Pretty simple solution, a magnitude script with a damage script on it, so basically like when it finds a zombie in range from the ‘‘ZombieFolder’’ it will aim at it and deal damage to it, BUT… i also want to make it so it shoots the one with the Lowest NumberValue and the other one Being the Highest NumberValue.
Issue is once all the time, I Don’t know the methods to code it.
this seems my best so far. i can change the ‘’ if distance < maxdistance then to if numbervalue is that and other is that lower or higher then shoot at it. i just need a way how to convert into that.
local tower = script.Parent
local mobs = workspace.Mobs
local humanoidnpc = script.Parent.Humanoid
local humanim = humanoidnpc:LoadAnimation(script.Parent.Shoot)
local function FindNearestTarget()
local maxDistance = 60
local nearestTarget = nil
for i, target in ipairs(mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - tower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
tower:SetPrimaryPartCFrame(CFrame.new(tower.PrimaryPart.Position,target.Torso.Position))
nearestTarget = target
maxDistance = distance
end
end
return nearestTarget
end
while true do
local target = FindNearestTarget()
if target then
humanim:Play()
script.Parent.ShootSound:Play()
target.Humanoid:TakeDamage(4)
wait(1)
script.Parent.Bolt:Play()
end
task.wait(4)
end
local function FindNearestTarget()
local maxDistance = 60
local nearestTarget = nil
local oldTargetNumber = math.huge() --here
local minimumTargetNumber = 1 --here
for i, target in ipairs(mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - tower.HumanoidRootPart.Position).Magnitude
if distance < maxDistance then
if target.TargetNumber.Value < oldTargetNumber and target.TargetNumber.Value > minimumTargetNumber then
tower:SetPrimaryPartCFrame(CFrame.new(tower.PrimaryPart.Position,target.Torso.Position))
nearestTarget = target
maxDistance = distance
end
end
end
return nearestTarget
end