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 » Scripters
Home Search
 

Re: Weighted Tables

Previous Thread :: Next Thread 
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:09 AM
Alright so if every player has a value called Weight how would I make a script that picks the player with the highest weight?
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:09 AM
Weight is a value by the way and every time someone doesn't get picked their weight will go up by 1.
Report Abuse
AdvancedObjects is not online. AdvancedObjects
Joined: 11 Dec 2012
Total Posts: 3354
12 Feb 2016 12:12 AM
Haven't tested it but pretty sure it's something along these lines:

local weights = {}
for _, player in pairs (game.Players:GetChildren()) do
local weight = player:FindFirstChild("Weight")
if weight then
table.insert(weights)
end
end
table.concat(weights)

local highest = weights[#weights]







Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:22 AM
Weight is a NumberValue, so how would I interpret that script to that that into account? Thanks a ton!
Report Abuse
Moronism is not online. Moronism
Joined: 08 Feb 2010
Total Posts: 451
12 Feb 2016 12:24 AM
I suppose that an algorithm to store the numerical values of each Player within a data-structure should suffice.

You could perhaps consider doing something such as this:

Weights = {Player_One.Weight.Value,Player_Two.Weight.Value};

Greatest = math.max(Weights[1],Weights[2]);
Report Abuse
AdvancedObjects is not online. AdvancedObjects
Joined: 11 Dec 2012
Total Posts: 3354
12 Feb 2016 12:41 AM
Oh, sorry my mistake. Put the value into the table not the actual instance.

table.insert(weight.Value)*



Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:48 AM
Alright so I got it to work by tweaking it a bit but now there is 1 issue standing, how do I get the player with the highest value? I got the highest value but I don't have the player.

local QueueWeight = {}

function WeightTest()
for _,player in pairs(game.Players:GetChildren()) do
local weight = player:FindFirstChild("Weight")
if weight then
table.insert(QueueWeight,weight.Value)
table.concat(QueueWeight)
local highest = QueueWeight[#QueueWeight]
return highest
end
end
end
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 01:13 AM
Scratch that it doesn't work in multiplayer, when a players weight changes it still only prints the weight of the first player even if it is lower than another player, any help is appreciated!

function WeightTest()
for _,player in pairs(game.Players:GetChildren()) do
local weight = player:FindFirstChild("Weight")
if weight then
table.insert(QueueWeight,weight.Value)
table.concat(QueueWeight)
local Weights = (unpack(QueueWeight))
local Pick = math.max(unpack(QueueWeight))
return Pick
end
end
end

while true do
local ChosenOne = WeightTest()
print(ChosenOne)
wait(2)
end
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 01:33 AM
b1
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 02:02 AM
b2
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:23 PM
Day 2: b3
Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:24 PM
Current Script:
QueueWeight = {}

function WeightTest()
for _,player in pairs(game.Players:GetChildren()) do
local weight = player:FindFirstChild("Weight")
if weight then
table.insert(QueueWeight,weight.Value)
table.concat(QueueWeight)
local Weights = (unpack(QueueWeight))
local Pick = math.max(unpack(QueueWeight))
return Pick
end
end
end

while true do
local ChosenOne = WeightTest()
print(ChosenOne)
wait(2)
end
Report Abuse
cheesecake123456 is not online. cheesecake123456
Joined: 01 Jun 2009
Total Posts: 1529
12 Feb 2016 12:32 PM
function WeightTest()
local winner = 0
for _,player in pairs(game.Players:GetChildren()) do
local weight = player:FindFirstChild("Weight")
if weight and weight.Value > winner then
winner = weight.Value
end
end
return winner
end

while true do
local ChosenOne = WeightTest()
print(ChosenOne)
wait(2)
end



Report Abuse
PraetorianTheGod is not online. PraetorianTheGod
Joined: 02 May 2014
Total Posts: 814
12 Feb 2016 12:36 PM
Thanks!
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
12 Feb 2016 12:41 PM
Regarding the table, you can also do this

table.sort(tab, function(a,b)
return a > b
end

table.insert(tab,player.Weight.Value)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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