So for my game, i want to use KeyCode instead of always needing to click buttons.
However this is not very secure due to the LayoutOrder. Means that Button 1 (From list should have KeyCode 1) however button 2 activates.
table.sort(datatable, function(a,b)
return (-a.Price)>(-b.Price);
-- might be wrong on the operator here.
-- depending on if your sorting is ascending or descending,
-- you might need to use < instead of >.
end);
Loop through the table and create the buttons from that.
for i, e in datatable do
local layoutOrder = e;
local keycodeNum = i;
local button = <button path>:Clone();
button.Price.Text = e.Price;
button.LayoutOrder = layoutOrder;
local keycodeValue = Instance.new("NumberValue");
keycodeValue.Name = "KeyCode";
keycodeValue.Value = keycodeNum;
end;