|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
| |
|
| |
|
|
| 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 |
|
|
|
| 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 |
|
|
| |
|
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 |
|
|