Advertisement
VincentYee

Piano Script

May 27th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. local seat = script.Parent.Bench.Seat
  2. local sheetMusic = script.Parent.Piano.SheetMusic
  3. local occupant = nil
  4. local tune = nil
  5. local oldTune = nil
  6. local animation = nil
  7. local r6Anim = script.PlayingR6
  8. local r15Anim = script.PlayingR15
  9.  
  10. tunes = {
  11. "rbxassetid://224027197", -- Scott Joplin - The Strenuous Life
  12. }
  13.  
  14. seat.ChildAdded:Connect(function(obj)
  15. if obj.Name == "SeatWeld" then
  16. local player = game.Players:GetPlayerFromCharacter(obj.Part1.Parent)
  17. if player then
  18. local hum = player.Character:FindFirstChild("Humanoid")
  19. occupant = obj.Part1.Parent
  20. if hum.RigType == Enum.HumanoidRigType.R6 then
  21. animation = hum:LoadAnimation(r6Anim)
  22. else
  23. animation = hum:LoadAnimation(r15Anim)
  24. end
  25. animation:Play()
  26. end
  27. end
  28. end)
  29.  
  30. seat.ChildRemoved:Connect(function(obj)
  31. if obj.Name == "SeatWeld" then
  32. local player = game.Players:GetPlayerFromCharacter(obj.Part1.Parent)
  33. if player then
  34. animation:Stop()
  35. occupant = nil
  36. sheetMusic.Sound:Stop()
  37. end
  38. end
  39. end)
  40.  
  41. while wait(0.1) do
  42. if occupant ~= nil then
  43. repeat
  44. tune = tunes[math.random(1, #tunes)]
  45. until tune ~= oldTune
  46. oldTune = tune
  47. sheetMusic.Sound.SoundId = tune
  48. sheetMusic.Sound:Play()
  49. repeat
  50. wait()
  51. until not sheetMusic.Sound.Playing
  52. end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement