brianops1

PianoVideoSortingMethod

Oct 19th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.61 KB | None | 0 0
  1. local reversesort = false --this will just reverse the keys names
  2. local location = game.Workspace.Piano.Keys.Keys --Change this to where your piano keys are located
  3.  
  4. local positions = {}
  5. for i,v in pairs(location:GetChildren()) do
  6.     if v then
  7.         table.insert(positions,v.Position.x)
  8.     end
  9. end
  10.  
  11. if reversesort then
  12.     table.sort(positions,function(a,b) return a>b end)
  13. else
  14.     table.sort(positions)
  15. end
  16.  
  17. for a,b in pairs(positions) do
  18.     for i,v in pairs(location:GetChildren()) do
  19.         if v and v.Position.x == b then
  20.             v.Name = a
  21.             break
  22.         end
  23.     end
  24. end
Add Comment
Please, Sign In to add comment