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: Get highest number value

Previous Thread :: Next Thread 
greencoolman8 is not online. greencoolman8
Joined: 22 Sep 2012
Total Posts: 82
31 Jul 2014 05:04 PM
So I have a model full of number values. And I want to look for the highest value. As in numbers. Like:
value1 = 100
value2 = 2
value3 = 9
I want to find value1 cause it's the biggest.
Report Abuse
super10099 is not online. super10099
Joined: 30 Jan 2010
Total Posts: 1102
31 Jul 2014 05:06 PM
print(value1)
Report Abuse
Articerile is not online. Articerile
Joined: 19 Jun 2007
Total Posts: 4243
31 Jul 2014 05:06 PM
local values = model:GetChildren
local highestvalue = -1
local highestvalue2 = nil
for i = 1, #values do
if values[i].Value > highestvalue then
highestvalue = values[i].Value
highestvalue2 = values[i]
end
end
Report Abuse
xXIcanthinkofanameXx is not online. xXIcanthinkofanameXx
Joined: 05 May 2012
Total Posts: 857
31 Jul 2014 05:06 PM
local highestValue = math.max(value1, value2, value3)
print(highestValue)
> 100
Report Abuse
blockoo is not online. blockoo
Joined: 08 Nov 2007
Total Posts: 17202
31 Jul 2014 05:07 PM
highest = nil
for i, v in pairs(MODEL:GetChildren()) do
if (v.ClassName == "NumberValue") then
if (v.Value > highest.Value or highest == nil) then
highest = v
end
end
end
Report Abuse
xXIcanthinkofanameXx is not online. xXIcanthinkofanameXx
Joined: 05 May 2012
Total Posts: 857
31 Jul 2014 05:13 PM
Actually this might work better:

local highestValue
local values = {}

for i, v in pairs(model:GetChildren())
if v.ClassName == "NumberValue" then
table.insert(values, v.Value)
end
end

local highestValue = math.max(unpack(values))
Report Abuse
greencoolman8 is not online. greencoolman8
Joined: 22 Sep 2012
Total Posts: 82
31 Jul 2014 05:33 PM
Oh thanks
Report Abuse
greencoolman8 is not online. greencoolman8
Joined: 22 Sep 2012
Total Posts: 82
31 Jul 2014 07:01 PM
I have no idea if I'm doing it right..
local winnert = Instance.new("Model", script)
winnert.Name="PlayerDestroyValues"
for i,v in pairs(game.Players:GetPlayers()) do
local zxxx = Instance.new("NumberValue", winnert)
zxxx.Name="Destroys "..v.Name
zxxx.Value = v.Destroys.Value
end
for i,v in pairs(winnert:GetChildren()) do
local person = math.max(v.Value)
game.Workspace.Won.Value=string.sub(person.Name,10)
end

Now what I'm trying to do is:
Make a model in this script. Make all the player's score.
I use math.max to find the highest value. Then look for the person with that value.
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