Advertisement
simhwui

Untitled

Dec 27th, 2015
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.87 KB | None | 0 0
  1. wait(0.5)
  2. ExistingSounds = {}
  3. Player = game.Players.LocalPlayer
  4. Gui = script:WaitForChild("PianoGui")
  5. Humanoid = Player.Character.Humanoid
  6. Tools = Instance.new("Folder",game:service("ReplicatedStorage"))
  7. PlayingEnabled = false
  8. PianoSounds = {
  9. "233836579", --C/C#
  10. "233844049", --D/D#
  11. "233845680", --E/F
  12. "233852841", --F#/G
  13. "233854135", --G#/A
  14. "233856105", --A#/B
  15. }
  16.  
  17. ScriptReady = false
  18.  
  19. PianoId = nil
  20.  
  21. function Activate()
  22. PlayingEnabled = true
  23. Gui.Parent=Player.PlayerGui
  24. MakeKeyboardConnections()
  25. MakeGuiConnections()
  26. --SetCamera(Player.Character.Torso.CFrame)
  27. SetSounds(PianoSounds)
  28. --Player.Character.Torso.Anchored=true
  29. --Humanoid.PlatformStand=true
  30. for i,v in pairs(Player.Backpack:children()) do
  31. v.Parent=Tools
  32. end
  33. end
  34.  
  35. function Deactivate()
  36. PlayingEnabled = false
  37. BreakKeyboardConnections()
  38. BreakGuiConnections()
  39. --ReturnCamera()
  40. --Player.Character.Torso.Anchored=false
  41. --Humanoid.PlatformStand=false
  42. for i,v in pairs(ExistingSounds) do
  43. if v then
  44. v:Stop()
  45. v:Destroy()
  46. end
  47. end
  48. for i,v in pairs(Tools:children()) do
  49. v.Parent=Player.Backpack
  50. end
  51. Tools:Destroy()
  52. Gui.Parent=script
  53. wait(0.5)
  54. script:Destroy()
  55. end
  56.  
  57. function PlayNoteClient(note)
  58. PlayNoteSound(note)
  59. HighlightPianoKey(note)
  60. end
  61.  
  62. InputService = game:GetService("UserInputService")
  63. Mouse = Player:GetMouse()
  64. TextBoxFocused = false
  65. ShiftLock = false
  66.  
  67. function LetterToNote(key, shift)
  68. local letterNoteMap = "1!2@34$5%6^78*9(0qQwWeErtTyYuiIoOpPasSdDfgGhHjJklLzZxcCvVbBnm"
  69. local capitalNumberMap = ")!@#$%^&*("
  70. local letter = string.char(key)
  71. if shift then
  72. if tonumber(letter) then
  73. -- is a number
  74. letter = string.sub(capitalNumberMap, tonumber(letter) + 1, tonumber(letter) + 1)
  75. else
  76. letter = string.upper(letter)
  77. end
  78. end
  79. local note = string.find(letterNoteMap, letter, 1, true)
  80. if note then
  81. return note
  82. end
  83. end
  84.  
  85. function KeyDown(Object)
  86. if TextBoxFocused then return end
  87. local key = Object.KeyCode.Value
  88. local shift = InputService:IsKeyDown(304) == not ShiftLock
  89. if (key >= 97 and key <= 122) or (key >= 48 and key <= 57) then
  90. -- a letter was pressed
  91. local note = LetterToNote(key, shift)
  92. if note then PlayNoteClient(note) end
  93. elseif key == 8 then
  94. -- backspace was pressed
  95. Deactivate()
  96.  
  97. elseif key == "s" then
  98. -- space was pressed --changed to S
  99. ToggleSheets()
  100. elseif key == 13 then
  101. -- return was pressed
  102. ToggleCaps()
  103. end
  104. end
  105.  
  106. function Input(Object)
  107. local type = Object.UserInputType.Name
  108. local state = Object.UserInputState.Name -- in case I ever add input types
  109. if type == "Keyboard" then
  110. if state == "Begin" then
  111. KeyDown(Object)
  112. end
  113. end
  114. end
  115.  
  116. function TextFocus()
  117. TextBoxFocused = true
  118. end
  119. function TextUnfocus()
  120. TextBoxFocused = false
  121. end
  122.  
  123. KeyboardConnection = nil
  124. JumpConnection = nil
  125. FocusConnection = InputService.TextBoxFocused:connect(TextFocus) --always needs to be connected
  126. UnfocusConnection = InputService.TextBoxFocusReleased:connect(TextUnfocus)
  127.  
  128. function MakeKeyboardConnections()
  129. KeyboardConnection = InputService.InputBegan:connect(Input)
  130.  
  131. end
  132. function BreakKeyboardConnections()
  133. KeyboardConnection:disconnect()
  134. end
  135.  
  136. PianoGui = Gui.PianoGui
  137. SheetsGui = Gui:FindFirstChild("SheetsGui")
  138. SheetsVisible = false
  139.  
  140. function ShowSheets()
  141. SheetsGui:TweenPosition(
  142. UDim2.new(0.5, -380, 1, -610),
  143. Enum.EasingDirection.Out,
  144. Enum.EasingStyle.Sine,
  145. .5,
  146. true
  147. )
  148. end
  149. function HideSheets()
  150. SheetsGui:TweenPosition(
  151. UDim2.new(0.5, -380, 1, 0),
  152. Enum.EasingDirection.Out,
  153. Enum.EasingStyle.Sine,
  154. .5,
  155. true
  156. )
  157. end
  158. function ToggleSheets()
  159. SheetsVisible = not SheetsVisible
  160. if SheetsVisible then
  161. ShowSheets()
  162. else
  163. HideSheets()
  164. end
  165. end
  166.  
  167. function IsBlack(note)
  168. if note%12 == 2 or note%12 == 4 or note%12 == 7 or note%12 == 9 or note%12 == 11 then
  169. return true
  170. end
  171. end
  172.  
  173. function HighlightPianoKey(note)
  174. local keyGui = PianoGui.Keys[note]
  175. if IsBlack(note) then
  176. keyGui.BackgroundColor3 = Color3.new(50/255, 50/255, 50/255)
  177. else
  178. keyGui.BackgroundColor3 = Color3.new(200/255, 200/255, 200/255)
  179. end
  180. delay(.5, function() RestorePianoKey(note) end)
  181. end
  182.  
  183. function RestorePianoKey(note)
  184. local keyGui = PianoGui.Keys[note]
  185. if IsBlack(note) then
  186. keyGui.BackgroundColor3 = Color3.new(0, 0, 0)
  187. else
  188. keyGui.BackgroundColor3 = Color3.new(1, 1, 1)
  189. end
  190. end
  191.  
  192. function PianoKeyPressed(Object, note)
  193. local type = Object.UserInputType.Name
  194. if type == "MouseButton1" or type == "Touch" then
  195. PlayNoteClient(note)
  196. end
  197. end
  198.  
  199. function ExitButtonPressed(Object)
  200. local type = Object.UserInputType.Name
  201. if type == "MouseButton1" or type == "Touch" then
  202. Deactivate()
  203. end
  204. end
  205.  
  206. function SheetsButtonPressed(Object)
  207. local type = Object.UserInputType.Name
  208. if type == "MouseButton1" or type == "Touch" then
  209. ToggleSheets()
  210. end
  211. end
  212.  
  213. function SheetsEdited(property)
  214. if property == "Text" then
  215. local bounds = SheetsGui.Sheet.ScrollingFrame.TextBox.TextBounds
  216. --SheetsGui.Sheet.ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, math.max(14, bounds.Y))
  217. end
  218. end
  219.  
  220. function ToggleCaps()
  221. ShiftLock = not ShiftLock
  222. if ShiftLock then
  223. PianoGui.CapsButton.BackgroundColor3 = Color3.new(1, 170/255, 0)
  224. PianoGui.CapsButton.BorderColor3 = Color3.new(154/255, 103/255, 0)
  225. PianoGui.CapsButton.TextColor3 = Color3.new(1, 1, 1)
  226. else
  227. PianoGui.CapsButton.BackgroundColor3 = Color3.new(140/255, 140/255, 140/255)
  228. PianoGui.CapsButton.BorderColor3 = Color3.new(68/255, 68/255, 68/255)
  229. PianoGui.CapsButton.TextColor3 = Color3.new(180/255, 180/255, 180/255)
  230. end
  231. end
  232.  
  233. function CapsButtonPressed(Object)
  234. local type = Object.UserInputType.Name
  235. if type == "MouseButton1" or type == "Touch" then
  236. ToggleCaps()
  237. end
  238. end
  239.  
  240. PianoKeysConnections = {}
  241. ExitButtonConnection = nil
  242. SheetsButtonConnection = nil
  243. SheetsEditedConnection = nil
  244. CapsButtonConnection = nil
  245.  
  246. function MakeGuiConnections()
  247. for i, v in pairs(PianoGui.Keys:GetChildren()) do
  248. PianoKeysConnections[i] = v.InputBegan:connect(function(Object) PianoKeyPressed(Object, tonumber(v.Name)) end)
  249. end
  250. PianoGui.Buy.MouseButton1Click:connect(function() game:service("MarketplaceService"):PromptPurchase(Player,254415530) end)
  251. PianoGui.Teleport.MouseButton1Click:connect(function() game:service("TeleportService"):Teleport(233727153) end)
  252. ExitButtonConnection = PianoGui.ExitButton.InputBegan:connect(ExitButtonPressed)
  253. SheetsButtonConnection = PianoGui.SheetsButton.InputBegan:connect(SheetsButtonPressed)
  254. --SheetsEditedConnection = SheetsGui.Sheet.ScrollingFrame.TextBox.Changed:connect(SheetsEdited)
  255. CapsButtonConnection = PianoGui.CapsButton.InputBegan:connect(CapsButtonPressed)
  256. end
  257. function BreakGuiConnections()
  258. for i, v in pairs(PianoKeysConnections) do
  259. v:disconnect()
  260. end
  261.  
  262. ExitButtonConnection:disconnect()
  263. SheetsButtonConnection:disconnect()
  264. --SheetsEditedConnection:disconnect()
  265. CapsButtonConnection:disconnect()
  266. end
  267.  
  268. ContentProvider = game:GetService("ContentProvider")
  269.  
  270. LocalSounds = {
  271. "233836579", --C/C#
  272. "233844049", --D/D#
  273. "233845680", --E/F
  274. "233852841", --F#/G
  275. "233854135", --G#/A
  276. "233856105", --A#/B
  277. }
  278.  
  279. SoundFolder = script.SoundFolder
  280.  
  281. function PreloadAudio(sounds)
  282. for i, v in pairs(sounds) do
  283. ContentProvider:Preload("http://www.roblox.com/asset/?id="..v)
  284. end
  285. end
  286. function SetSounds(sounds)
  287. PreloadAudio(sounds)
  288. LocalSounds = sounds
  289. end
  290. function PlayNoteSound(note, source, range, sounds)
  291.  
  292. local SoundList = sounds or LocalSounds
  293.  
  294. local note2 = (note - 1)%12 + 1 -- Which note? (1-12)
  295.  
  296. local octave = math.ceil(note/12) -- Which octave?
  297.  
  298. local sound = math.ceil(note2/2) -- Which audio?
  299.  
  300. local offset = 16 * (octave - 1) + 8 * (1 - note2%2) -- How far in audio?
  301.  
  302. local audio = Instance.new("Sound", SoundFolder)-- Create the audio
  303. audio.SoundId = "https://roblox.com/asset/?id="..SoundList[sound] -- Give its sound
  304. audio.Volume = 1
  305.  
  306. if source then
  307. local a = 1/range^2
  308. local distance = (game.Workspace.CurrentCamera.CoordinateFrame.p - source).magnitude
  309. local volume = -a*distance^2 + 1
  310. if volume < 0.05 then
  311. audio:remove()
  312. return
  313. end
  314. audio.Volume = volume
  315. end--]]
  316. audio.TimePosition = offset + (octave - .9)/15 -- set the time position
  317. audio:Play() -- Play the audio
  318.  
  319. table.insert(ExistingSounds, 1, audio)
  320. if #ExistingSounds >= 10 then
  321. ExistingSounds[10]:Stop() -- limit the number of playing sounds!
  322. ExistingSounds[10] = nil
  323. end
  324.  
  325. delay(4, function() audio:Stop() audio:remove() end ) -- remove the audio in 4 seconds, enough time for it to play
  326. end
  327.  
  328. Camera = game.Workspace.CurrentCamera
  329.  
  330.  
  331. function SetCamera(cframe)
  332. Camera.CameraType = Enum.CameraType.Scriptable
  333. Camera:Interpolate(cframe, cframe + cframe.lookVector, .5)
  334. --Camera.CoordinateFrame = cframe
  335. end
  336. function ReturnCamera()
  337. Camera.CameraType = Enum.CameraType.Custom
  338. end
  339.  
  340. ScriptReady = true
  341. Humanoid.Died:connect(Deactivate)
  342. Activate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement