How to get first obj from for loops?

i know how how to get the first obj from the loop
heres my code

local getchar = workspace:GetDescendants()
					
					for i,part in pairs(getchar) do
						if part:FindFirstChild("Humanoid")  and i < 2 then
							print(part[i])
							
						end
						
					end
1 Like

Can you explain “first object” means, like the the first few things it prints?

The first obj is the character closest to me

Is this in a localscript? just a question.

is a script , i dont know how to fix

Sorry for being late, make a magnitude check.

The first thing you want to do is to sort every object by it’s Player:DistanceFromCharacter(object). Lowest values goes first. Usually you want to sort this with a dictionary, where the keys are objects while the values are distances.

However, the issue is that you cannot run this loop forever, as it is very expensive to get all the descendants of workspace. Why are you trying this in the first place?

1 Like