Hi guys, im trying to code a find nearest target script and apparently i can't properly save my humanoidrootpart properly here's the code(I"ll remove as much redundant code as possible):
function FindNearestTarget() local list = game.Workspace:GetChildren() for i=1, #list do if list[i].ClassName == "Model" and list[i]:FindFirstChild("Humanoid") then TargetPos = {list[i].HumanoidRootPart.Position} wait(1) end end if TargetPos then print (unpack(TargetPos)) end end--Function End
The above code apparently results in TargetPos to only have 1 element regardless of the number of players in the game. If this function was ran in an infinite loop, and there are 2 players for example, TargetPos seems to replace it's first element with the next player's position, then go back to printing the first player's position. I want to be able to print (TargetPos[2]) but it always result in a nil because it was never saved as the second element in the first place. any idea whats wrong?