generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: find highest value?

Previous Thread :: Next Thread 
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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 is not online. 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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 12:39 PM
cmon guys,how would I do this??
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 12:40 PM
math.max?never heard of it :\
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 12:40 PM
it already creates the value for kills btw,i want to see which one is highest...
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
Drybones3363 is not online. Drybones3363
Joined: 16 Aug 2013
Total Posts: 1547
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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 12:53 PM
dang.BUMP
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 12:55 PM
another bBuUmMpP(can you see both bumps?)
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 12:57 PM
bumpity BUMPITY BUMPP
cmon,i need help
Report Abuse
Notunknown99 is not online. Notunknown99
Joined: 05 Sep 2008
Total Posts: 25360
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
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
11 Jan 2014 01:06 PM
thx man
Report Abuse
Majorhappenings is not online. Majorhappenings
Joined: 25 Dec 2013
Total Posts: 299
11 Jan 2014 01:45 PM
yes! math.max returns the highest value.

print(math.max(5, 10))

prints 10
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image