|
| 11 Jan 2014 12:37 PM |
so,everytime someone joins,it creates a numbervalue called "playername"'s kills anyway,so how would I check which number value is the highest? like.. while wait(0.10 do z = Workspace.Model:GetChildren() --find the highest value here? end
sorry,but im lostttt |
|
|
| Report Abuse |
|
|
Azureous
|
  |
| Joined: 29 Jan 2012 |
| Total Posts: 25287 |
|
|
| 11 Jan 2014 12:39 PM |
make a table check using math.max is what I would do |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:39 PM |
| cmon guys,how would I do this?? |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:40 PM |
| math.max?never heard of it :\ |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:40 PM |
| it already creates the value for kills btw,i want to see which one is highest... |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:41 PM |
To follow up on Azureous' suggestion, you can use the unpack function and math.max function to do what you want.
local scores = { 5, 4, 8, 1, 2, 0 } print( math.max(unpack(scores)) ) --> 8 |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:41 PM |
| use a intnumber instance or something like that and change the value from each player if theirs is higher |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:42 PM |
so would it be like..
local scores = { Workspace.Model:GetChildren()} print( math.max(unpack(scores)) )
or something similar? |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:44 PM |
Similar, but you need to extract the values first. We can't use math function on objects.
local scores = {} for _, v in pairs(Workspace.Model:GetChildren()) do table.insert(scores, v.Value) -- assuming only number/int values are in Model end local highest = math.max(unpack(scores)) |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:47 PM |
ok so it prints the highest value:
local scores = {} for _, v in pairs(Workspace.kills:GetChildren()) do table.insert(scores, v.Value) -- assuming only number/int values are in Model end local highest = math.max(unpack(scores)) print (highest)
but how would I make it print numbervalue.name with highest score wins! that sorta thing? |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Jan 2014 12:55 PM |
| another bBuUmMpP(can you see both bumps?) |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 12:57 PM |
bumpity BUMPITY BUMPP cmon,i need help |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 01:00 PM |
You could do this:
local values = modelContainingValues:GetChildren()
table.sort(values, function(a, b) return a.Value > b.Value end)
print(unpack(values)) |
|
|
| Report Abuse |
|
|
| |
|
|
| 11 Jan 2014 01:45 PM |
yes! math.max returns the highest value.
print(math.max(5, 10))
prints 10 |
|
|
| Report Abuse |
|
|
|
| 11 Jan 2014 02:14 PM |
"You could do this:
local values = modelContainingValues:GetChildren()
table.sort(values, function(a, b) return a.Value > b.Value end)
print(unpack(values))"
Didn't even think about table.sort ... Well played, fellow scripter. |
|
|
| Report Abuse |
|
|