I need it to go up to 20 people, so would it be any different than just three?
It needs to constantly update as there position/closeness to the part changes
First, you’re gonna need to get the position of every player’s HumanoidRootPart in their character. Then, get the position of the part that you are racing towards and use .Magnitude to find the distance.
Next, put these magnitude values in the table, sort the table from the smallest to greatest value, and then print out the names.
i would do smth like this
use a timer module when the race starts
when the player touches the end mark the timer and print the players name with the time
You use the table.sort function to sort a table from least to greatest. The DevHub doesn’t have a great explanation on it, but @EmbatTheHybrid does a really good job explaining how to use table.sort in this post:
Here a table sorting function I made to sort random numbers from least to greatest:
local t = {15,7,66,93,10}
table.sort(t, function(a,b)
return a < b
end)
print(t)
To do it simpler if wanted, if you’re wanting a least to greatest/ascending order sort, you don’t even need to give a function as the default sorting uses <, but if you wanted to do a descending sort, you’d need to make a function
And I know I’m kinda asking for a bit, but how do you get each individual position by itself? A
My example is that the person in first has a name tag in there character, which I want to assign “1st Player1Name” as the text value. And for second “2nd Player2Name”.
Think what you can do after getting the positions of each player and sorting to get the top 3, you can reference their character and change the tag there
This will require you to store a key value dictionary in the table, where the key is the character and the value is the distance
So say you have 1 player who is 10 studs away from soemthing, their entry in the table would be
{key = workspace.Player1, value = 10}
Then in the table.sort, you need to reference that