So i made a similar post here, but it has some complications.
Anyways to make a magnitude script that only targets in a specified folder so it chooses only the one with the strongest health or the weakest health, making it print the one thats weakest or strongest. how do i do something like this that is magnitudal and counts each humanoid in a folder.
how do i do something like so it chooses the strongest or the weakest, in like a folder magnitude script.
You loop through all the folderâs humanoids and then you store them somewhere like a table to compare them all to eachother. Then you check which one is the weakest and which one is the strongest and you choose the target.
Be sure to store the location of the humanoid too, cause then you can get both the humanoidâs strength and its location (workspace or something like that).
As @BandQueenForever said, loop through all the Folder with all of the other Folders inside by using :GetDescendants() which will allow you to get every single content inside of the Folder. Then inside the loop, you would make few if statements by checking if there is a Health value inside. I am not sure what kind of logic you want to approach for checking the weakest and strongest Humanoid, but the simplest one would be to just check if Health Value is 100, then that is the strongest Humanoid.
Once you find a Strongest Humanoid, you can use a Magnitude Value between your Character and the NPC. Check if Magnitude Value is below a specified number and then do something.
while wait(0.3) do
local towertorso = script.Parent.Torso
local mobs = workspace.Enemies
local humanoid = script.Parent.Humanoid
local humanoidnpc = script.Parent.Humanoid
--local humanim = humanoidnpc:LoadAnimation(script.Parent.fire)
local function FindFirstTarget()
local maxDistance = 150
local nearestTarget = nil
for i, target in ipairs(mobs:GetChildren()) do
local distance = (target.HumanoidRootPart.Position - towertorso.Position).Magnitude
if target.DistanceToWaypoint.Value < 999 and target.MovingValue.Value > 0 then
towertorso.Parent:SetPrimaryPartCFrame(CFrame.new(towertorso.Parent.PrimaryPart.Position,target.Torso.Position))
maxDistance = distance
end
end
end
while true do
local target = FindFirstTarget()
local FireSound = Instance.new('Sound')
local damagenumber = 3
if target then
-- Do something
end
task.wait(0.5)
end
end
You can try using table.insert() to insert the specified Humanoid to be shot at. After that you can just loop through the new table of the Specified Humanoids.
Assuming you already have a table of humanoids, you can loop through them and keep setting variables to find which one has the least/most value (then return it). Iâd do this:
function SortHumanoids(Humanoids,Mode) -- Mode is either "Least" or "Most"
local selected = nil
local healthThreshold
if Mode == "Least" then
HealthThreshold = math.huge
for i,v in pairs(Humanoids) do
if v.Health < HealthThreshold then
HealthThreshold = v.Health
selected = v
end
end
elseif Mode == "Most" then
HealthThreshold = -math.huge
for i,v in pairs(Humanoids) do
if v.Health > HealthThreshold then
HealthThreshold = v.Health
selected = v
end
end
end
return selected
end
That depends on your logic, all this function does is take an array of humanoids (e.g. {Humanoid, Humanoid, Humanoid}) and gives you which one has the most/least health.