Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How To Find Highest Value Then Add to table?

I Need Help On creating A script, I'm not sure how'd you do this. There is a Folder. Here is the Format

Script.Players(Folder).Player(NumValue)

Player Is Set Up as Name = Player Name And Value = Value

So What I am trying to say is something like this,

for i=1,HowManyDoIFind.Value  do
Find Highest Value
Return The Value And The Name
Insert Name And Values In Order On Table Named "Scores"
end

And Whenever I Need The 1st Winner Or 5th Winner, I just Access The Table. Problem Is I Don't Know How to make the script.

2 comments

0

Show us your attempt

2

He made an attempt at PsuedoCode if that counts .-.

1 answer

✓ Accepted answer

The simplest way to accomplish this would be sort the list of Player NumberValues.

To sort, you need a list:

local scores = script.Players:GetChildren()

and a way to compare two things (a function). This function is supposed to return true if first should be ranked before second:

function compare(first, second)
	return first.Value > second.Value
end

Now you just call table.sort using scores and compare:

table.sort(scores, compare)

and then scores[1] is the highest scoring player, up to scores[#scores]:

for i = 1, #scores do
	print(i .. "st", scores[i].Name, "scored", scores[i].Value, "points")
end

This discussion is preserved as it was. New answers, comments, and votes are closed.