How do i make a tower script for a tower defense game so it either aims one with the highest value or the lowest value or both

in your script the final result is set to the enemy variable just print its value after the loop

after the loop? thats not what i meant, i want it to print all zombies in a folder so if one of them has a highest value or a lowest value then, it only prints the zombie with the HIGHEST value, not starting 0 to 100 printing like all the zombies.
Is this the wrong technique or the right one, i don’t understand.

thats what the loop does!!! it will loop theough your enemies then check if their number value is higher than the stored one

if you print the enemy value after the loop it will give you the HIGHEST value

you just explained in extra detail what i just said

your print is INSIDE the IF STATEMENT making it print everytime it finds a value higher than the last, which is basically lowest to highest

then how do i avoid the loop pattern?

put
the
print
after
the
loop

hfhdhdhdh

but, how do i do that though, somehow putting in it between 2 ends just has the same result, making it out of the loop doesn’t even give result and just give orange lines in the code.

AFTER

-- loop goes here
for i, v in pairs(enemies:GetChildren())
end)
-- this is after
print(enemy.Value)

thanks, it works now, hopefully its efficent now.
:slightly_smiling_face:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.