Hello, i am working on a game and have decided to implement an NPC which will take appearance of a player with the highest cash in the server.
Currently i am using the "GetCharacterAppearanaceAsync()" function. This function works and i have made it take appearance of me at the moment but i'd like this npc to take appearance of the player as mentioned in the title of this question.
I know how to find userIDs from usernames but what im stuck on is the comparing of the leaderstats; Do i use a linear search/Binary search/etc and if so how would i code it to connect with the leaderstats to find the highest score then match that score to the player with it?
In this scenario i am wanting the Cash to be compared considering this is the only stat i currently have on my game as of so far.
Thankyou very much for taking your time to read this :P

11 comments
Yeah, that is kinda what i was thinking but i tried it but it had an error. But it looks like you've done it a different way so i'll try your method.
Also, what is the difference 'in pairs' and 'in ipairs'
it errors: bad argument #1 to 'ipairs' (table expected, got Object)
I fixed it. I added ":GetPlayers()" at the end of line 04 after the "Players" part
'ipairs' uses the order in the index for the index variable, while 'pairs' uses the key for the index variable. Sorry about that typo on line 4. Guess I overlooked it.
Its fine. You've helped me out alot. btw whilst we're here. I've encountered another problem. I am using local userID = game.Players:GetUserIdFromNameAsync(TopPlayer) then converting that userid to change the appearance of an npc. However that id is not the id used on my profile. Ik this coz my profile id on roblox is "22984342" and it is coming up with "73502"
You don't need to use the function. This would work: local userID = TopPlayer.UserId
oh right. Would that get me the 22984342 id?
It should if you have the most money.
Yup, Sweet thankyou soo much. Ill know that for future now as well. BRILLIANT! :D
Your welcome. Good luck on your game!