Advertisement
brianops1

EndResult

Oct 19th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.43 KB | None | 0 0
  1. Settings = require(script.Parent.Settings)
  2. Piano = script.Parent
  3. Box = Piano.Keys.KeyBox
  4.  
  5. ----------------------------------
  6. ----------------------------------
  7. ----------------------------------
  8. ---------PIANO CONNECTION---------
  9. ----------------------------------
  10. ----------------------------------
  11. ----------------------------------
  12.  
  13. ----------------------------------
  14. ------------VARIABLES-------------
  15. ----------------------------------
  16.  
  17. User = nil
  18.  
  19. Connector = game.Workspace:FindFirstChild("GlobalPianoConnector")
  20. if not Connector or not Connector:IsA("RemoteEvent") then
  21.     error("The piano requires a RemoteEvent named GlobalPianoConnector to be in Workspace.")
  22. end
  23.  
  24. ----------------------------------
  25. ------------FUNCTIONS-------------
  26. ----------------------------------
  27.  
  28. function Receive(player, action, ...)
  29.     local args = {...}
  30.     if player == User and action == "play" then
  31.         Connector:FireAllClients("play", User, args[1], Settings.SoundSource.Position, Settings.PianoSoundRange, Settings.PianoSounds, args[2], Settings.IsCustom)
  32.         HighlightPianoKey((args[1] > 61 and 61) or (args[1] < 1 and 1) or args[1],args[3])
  33.     elseif player == User and action == "abort" then
  34.         Deactivate()
  35.         if SeatWeld then
  36.             SeatWeld:remove()
  37.         end
  38.     end
  39. end
  40.  
  41. function Activate(player)
  42.     Connector:FireClient(player, "activate", Settings.CameraCFrame, Settings.PianoSounds, true)
  43.     User = player
  44. end
  45.  
  46. function Deactivate()
  47.     if User and User.Parent then
  48.         Connector:FireClient(User, "deactivate")
  49.         User.Character:SetPrimaryPartCFrame(Box.CFrame + Vector3.new(0, 5, 0))
  50.     end
  51.    
  52.     User = nil
  53. end
  54.  
  55. ----------------------------------
  56. -----------CONNECTIONS------------
  57. ----------------------------------
  58.  
  59. Connector.OnServerEvent:connect(Receive)
  60.  
  61. ----------------------------------
  62. ----------------------------------
  63. ----------------------------------
  64. ----------SEAT MECHANISM----------
  65. ----------------------------------
  66. ----------------------------------
  67. ----------------------------------
  68.  
  69. ----------------------------------
  70. ------------VARIABLES-------------
  71. ----------------------------------
  72.  
  73. Seat = script.Parent.Bench.Seat
  74. SeatWeld = nil
  75.  
  76.  
  77. ----------------------------------
  78. ------------FUNCTIONS-------------
  79. ----------------------------------
  80.  
  81. function WeldChanged(property)
  82.     if property == "Parent" and SeatWeld.Parent == nil then
  83.         SeatWeld = nil
  84.         Deactivate()
  85.         BreakSeatConnections()
  86.         Piano.Bench.Seat.Disabled = true
  87.         wait(1)
  88.         Piano.Bench.Seat.Disabled = false
  89.     end
  90. end
  91. function ChildAdded(child)
  92.     if child:IsA("Weld") then
  93.         local root = child.Part1
  94.         local character = root.Parent
  95.         local player = game.Players:GetPlayerFromCharacter(character)
  96.         if player then
  97.             SeatWeld = child
  98.             Activate(player)
  99.             MakeSeatConnections()
  100.         end
  101.     end
  102. end
  103.  
  104. ----------------------------------
  105. -----------CONNECTIONS------------
  106. ----------------------------------
  107.  
  108. SeatWeldConnection = nil
  109.  
  110. function MakeSeatConnections()
  111.     SeatWeldConnection = SeatWeld.Changed:connect(WeldChanged)
  112. end
  113. function BreakSeatConnections()
  114.     SeatWeldConnection:disconnect()
  115. end
  116.  
  117. Seat.ChildAdded:connect(ChildAdded)
  118.  
  119. ----------------------------------
  120. ----------------------------------
  121. ----------------------------------
  122. ------------AESTHETICS------------
  123. ----------------------------------
  124. ----------------------------------
  125. ----------------------------------
  126.  
  127. ----------------------------------
  128. ------------VARIABLES-------------
  129. ----------------------------------
  130.  
  131. Keys = script.Parent.Keys
  132.  
  133.  
  134. ----------------------------------
  135. ------------FUNCTIONS-------------
  136. ----------------------------------
  137.  
  138. function UnDigify(digit)
  139.     if digit < 1 or digit > 61 then
  140.         return ""
  141.     elseif digit == 1 then
  142.         return "1"
  143.     elseif digit == 2 then
  144.         return "!"
  145.     elseif digit == 3 then
  146.         return "2"
  147.     elseif digit == 4 then
  148.         return "@"
  149.     elseif digit == 5 then
  150.         return "3"
  151.     elseif digit == 6 then
  152.         return "4"
  153.     elseif digit == 7 then
  154.         return "$"
  155.     elseif digit == 8 then
  156.         return "5"
  157.     elseif digit == 9 then
  158.         return "%"
  159.     elseif digit == 10 then
  160.         return "6"
  161.     elseif digit == 11 then
  162.         return "^"
  163.     elseif digit == 12 then
  164.         return "7"
  165.     elseif digit == 13 then
  166.         return "8"
  167.     elseif digit == 14 then
  168.         return "*"
  169.     elseif digit == 15 then
  170.         return "9"
  171.     elseif digit == 16 then
  172.         return "("
  173.     elseif digit == 17 then
  174.         return "0"
  175.     elseif digit == 18 then
  176.         return "q"
  177.     elseif digit == 19 then
  178.         return "Q"
  179.     elseif digit == 20 then
  180.         return "w"
  181.     elseif digit == 21 then
  182.         return "W"
  183.     elseif digit == 22 then
  184.         return "e"
  185.     elseif digit == 23 then
  186.         return "E"
  187.     elseif digit == 24 then
  188.         return "r"
  189.     elseif digit == 25 then
  190.         return "t"
  191.     elseif digit == 26 then
  192.         return "T"
  193.     elseif digit == 27 then
  194.         return "y"
  195.     elseif digit == 28 then
  196.         return "Y"
  197.     elseif digit == 29 then
  198.         return "u"
  199.     elseif digit == 30 then
  200.         return "i"
  201.     elseif digit == 31 then
  202.         return "I"
  203.     elseif digit == 32 then
  204.         return "o"
  205.     elseif digit == 33 then
  206.         return "O"
  207.     elseif digit == 34 then
  208.         return "p"
  209.     elseif digit == 35 then
  210.         return "P"
  211.     elseif digit == 36 then
  212.         return "a"
  213.     elseif digit == 37 then
  214.         return "s"
  215.     elseif digit == 38 then
  216.         return "S"
  217.     elseif digit == 39 then
  218.         return "d"
  219.     elseif digit == 40 then
  220.         return "D"
  221.     elseif digit == 41 then
  222.         return "f"
  223.     elseif digit == 42 then
  224.         return "g"
  225.     elseif digit == 43 then
  226.         return "G"
  227.     elseif digit == 44 then
  228.         return "h"
  229.     elseif digit == 45 then
  230.         return "H"
  231.     elseif digit == 46 then
  232.         return "j"
  233.     elseif digit == 47 then
  234.         return "J"
  235.     elseif digit == 48 then
  236.         return "k"
  237.     elseif digit == 49 then
  238.         return "l"
  239.     elseif digit == 50 then
  240.         return "L"
  241.     elseif digit == 51 then
  242.         return "z"
  243.     elseif digit == 52 then
  244.         return "Z"
  245.     elseif digit == 53 then
  246.         return "x"
  247.     elseif digit == 54 then
  248.         return "c"
  249.     elseif digit == 55 then
  250.         return "C"
  251.     elseif digit == 56 then
  252.         return "v"
  253.     elseif digit == 57 then
  254.         return "V"
  255.     elseif digit == 58 then
  256.         return "b"
  257.     elseif digit == 59 then
  258.         return "B"
  259.     elseif digit == 60 then
  260.         return "n"
  261.     elseif digit == 61 then
  262.         return "m"
  263.     else
  264.         return "?"
  265.     end
  266. end
  267. function IsBlack(note)
  268.     if note%12 == 2 or note%12 == 4 or note%12 == 7 or note%12 == 9 or note%12 == 11 then
  269.         return true
  270.     end
  271. end
  272.  
  273. local TweenService = game:GetService("TweenService")
  274. function Tween(obj,Goal,Time,Wait,...) local TwInfo = TweenInfo.new(Time,...) local twn = TweenService:Create(obj, TwInfo, Goal) twn:Play() if Wait then twn.Completed:wait() end return
  275. end
  276.  
  277. local orgins = {} if script.Parent.Keys:FindFirstChild("Keys") then for i,v in pairs(script.Parent.Keys.Keys:GetChildren()) do orgins[v.Name] = {v.Position,v.Orientation} end else for i,v in pairs(script.Parent.Keys:GetChildren()) do if v:IsA("Model") then for a,b in pairs(v:GetChildren()) do orgins[v.Name] = {b.Position,b.Orientation} end end end end function AnimateKey(note1,px,py,pz,ox,oy,oz,Time) pcall(function() local obj = script.Parent.Keys.Keys:FindFirstChild(note1) if obj then local Properties = {} local OrginP = orgins[obj.Name][1] local OrginO = orgins[obj.Name][2] local changep = OrginP - Vector3.new(px,py,pz) local changeo = OrginO - Vector3.new(ox,oy,oz) Properties.Position = Vector3.new(obj.Position.x, changep.Y, changep.Z) Properties.Orientation = changeo Tween(obj,Properties,Time,Enum.EasingStyle.Linear) Properties = {} Properties.Position = Vector3.new(obj.Position.x,OrginP.y,OrginP.z) Properties.Orientation = OrginO Tween(obj,Properties,Time,Enum.EasingStyle.Linear) else print(note1..' was not found, or you do not have the correct configuration for the piano keys') end end) end
  278. --[[
  279. AnimateKey(note1,px,py,pz,ox,oy,oz,Time)
  280. --note1(1-61), position x, position y, position z, orientation x, orientation y, orientation z, time
  281.  
  282. local obj = --object or gui or wahtever goes here
  283. local Properties = {}
  284. Properties.Size = UDim2.new()
  285. Tween(obj,Properties,2,true,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false)
  286. --Obj,Property,Time,wait,Easingstyle,EasingDirection,RepeatAmt,Reverse
  287. ]]
  288.  
  289. function HighlightPianoKey(note1,transpose)
  290.     if not Settings.KeyAesthetics then return end
  291.     local octave = math.ceil(note1/12)
  292.     local note2 = (note1 - 1)%12 + 1
  293.     if IsBlack(note1) then
  294.         print('hit')
  295. --note1(1-61), position x, position y, position z, orientation x, orientation y, orientation z, time
  296.     else
  297.         AnimateKey(note1,0,.06,0,-6,0,0,.15)
  298. --note1(1-61), position x, position y, position z, orientation x, orientation y, orientation z, time
  299.     end
  300. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement