What you want to do is index by a specific field. You might know this as a "dictionary" or a "hash table".
For example
players = {}
for i, v in pairs(game:GetService("Players"):GetPlayers()) do
players[v.Name] = v
end
Now if we want to get a player from their name, instead of doing this...
targetName = "Bob"
player = nil
for i, v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Name == targetName then
player = v
break
end
end
...which is O(n), we can do this...
player = players[targetName]
...which is a constant time look up, regardless of how many elements are in your data structure.
It's not a great example but the idea is always the same. I'd make it more specific but you haven't given a lot to go on.
3 comments
without knowing its index
wait nvm i have an idea
Okay