Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Settings = require(script.Parent.Settings)
- Piano = script.Parent
- Box = Piano.Keys.KeyBox
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ---------PIANO CONNECTION---------
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ------------VARIABLES-------------
- ----------------------------------
- User = nil
- Connector = game.Workspace:FindFirstChild("GlobalPianoConnector")
- if not Connector or not Connector:IsA("RemoteEvent") then
- error("The piano requires a RemoteEvent named GlobalPianoConnector to be in Workspace.")
- end
- ----------------------------------
- ------------FUNCTIONS-------------
- ----------------------------------
- function Receive(player, action, ...)
- local args = {...}
- if player == User and action == "play" then
- Connector:FireAllClients("play", User, args[1], Settings.SoundSource.Position, Settings.PianoSoundRange, Settings.PianoSounds, args[2], Settings.IsCustom)
- HighlightPianoKey((args[1] > 61 and 61) or (args[1] < 1 and 1) or args[1],args[3])
- elseif player == User and action == "abort" then
- Deactivate()
- if SeatWeld then
- SeatWeld:remove()
- end
- end
- end
- function Activate(player)
- Connector:FireClient(player, "activate", Settings.CameraCFrame, Settings.PianoSounds, true)
- User = player
- end
- function Deactivate()
- if User and User.Parent then
- Connector:FireClient(User, "deactivate")
- User.Character:SetPrimaryPartCFrame(Box.CFrame + Vector3.new(0, 5, 0))
- end
- User = nil
- end
- ----------------------------------
- -----------CONNECTIONS------------
- ----------------------------------
- Connector.OnServerEvent:connect(Receive)
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ----------SEAT MECHANISM----------
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ------------VARIABLES-------------
- ----------------------------------
- Seat = script.Parent.Bench.Seat
- SeatWeld = nil
- ----------------------------------
- ------------FUNCTIONS-------------
- ----------------------------------
- function WeldChanged(property)
- if property == "Parent" and SeatWeld.Parent == nil then
- SeatWeld = nil
- Deactivate()
- BreakSeatConnections()
- Piano.Bench.Seat.Disabled = true
- wait(1)
- Piano.Bench.Seat.Disabled = false
- end
- end
- function ChildAdded(child)
- if child:IsA("Weld") then
- local root = child.Part1
- local character = root.Parent
- local player = game.Players:GetPlayerFromCharacter(character)
- if player then
- SeatWeld = child
- Activate(player)
- MakeSeatConnections()
- end
- end
- end
- ----------------------------------
- -----------CONNECTIONS------------
- ----------------------------------
- SeatWeldConnection = nil
- function MakeSeatConnections()
- SeatWeldConnection = SeatWeld.Changed:connect(WeldChanged)
- end
- function BreakSeatConnections()
- SeatWeldConnection:disconnect()
- end
- Seat.ChildAdded:connect(ChildAdded)
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ------------AESTHETICS------------
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ----------------------------------
- ------------VARIABLES-------------
- ----------------------------------
- Keys = script.Parent.Keys
- ----------------------------------
- ------------FUNCTIONS-------------
- ----------------------------------
- function UnDigify(digit)
- if digit < 1 or digit > 61 then
- return ""
- elseif digit == 1 then
- return "1"
- elseif digit == 2 then
- return "!"
- elseif digit == 3 then
- return "2"
- elseif digit == 4 then
- return "@"
- elseif digit == 5 then
- return "3"
- elseif digit == 6 then
- return "4"
- elseif digit == 7 then
- return "$"
- elseif digit == 8 then
- return "5"
- elseif digit == 9 then
- return "%"
- elseif digit == 10 then
- return "6"
- elseif digit == 11 then
- return "^"
- elseif digit == 12 then
- return "7"
- elseif digit == 13 then
- return "8"
- elseif digit == 14 then
- return "*"
- elseif digit == 15 then
- return "9"
- elseif digit == 16 then
- return "("
- elseif digit == 17 then
- return "0"
- elseif digit == 18 then
- return "q"
- elseif digit == 19 then
- return "Q"
- elseif digit == 20 then
- return "w"
- elseif digit == 21 then
- return "W"
- elseif digit == 22 then
- return "e"
- elseif digit == 23 then
- return "E"
- elseif digit == 24 then
- return "r"
- elseif digit == 25 then
- return "t"
- elseif digit == 26 then
- return "T"
- elseif digit == 27 then
- return "y"
- elseif digit == 28 then
- return "Y"
- elseif digit == 29 then
- return "u"
- elseif digit == 30 then
- return "i"
- elseif digit == 31 then
- return "I"
- elseif digit == 32 then
- return "o"
- elseif digit == 33 then
- return "O"
- elseif digit == 34 then
- return "p"
- elseif digit == 35 then
- return "P"
- elseif digit == 36 then
- return "a"
- elseif digit == 37 then
- return "s"
- elseif digit == 38 then
- return "S"
- elseif digit == 39 then
- return "d"
- elseif digit == 40 then
- return "D"
- elseif digit == 41 then
- return "f"
- elseif digit == 42 then
- return "g"
- elseif digit == 43 then
- return "G"
- elseif digit == 44 then
- return "h"
- elseif digit == 45 then
- return "H"
- elseif digit == 46 then
- return "j"
- elseif digit == 47 then
- return "J"
- elseif digit == 48 then
- return "k"
- elseif digit == 49 then
- return "l"
- elseif digit == 50 then
- return "L"
- elseif digit == 51 then
- return "z"
- elseif digit == 52 then
- return "Z"
- elseif digit == 53 then
- return "x"
- elseif digit == 54 then
- return "c"
- elseif digit == 55 then
- return "C"
- elseif digit == 56 then
- return "v"
- elseif digit == 57 then
- return "V"
- elseif digit == 58 then
- return "b"
- elseif digit == 59 then
- return "B"
- elseif digit == 60 then
- return "n"
- elseif digit == 61 then
- return "m"
- else
- return "?"
- end
- end
- function IsBlack(note)
- if note%12 == 2 or note%12 == 4 or note%12 == 7 or note%12 == 9 or note%12 == 11 then
- return true
- end
- end
- local TweenService = game:GetService("TweenService")
- 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
- end
- 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
- --[[
- AnimateKey(note1,px,py,pz,ox,oy,oz,Time)
- --note1(1-61), position x, position y, position z, orientation x, orientation y, orientation z, time
- local obj = --object or gui or wahtever goes here
- local Properties = {}
- Properties.Size = UDim2.new()
- Tween(obj,Properties,2,true,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false)
- --Obj,Property,Time,wait,Easingstyle,EasingDirection,RepeatAmt,Reverse
- ]]
- function HighlightPianoKey(note1,transpose)
- if not Settings.KeyAesthetics then return end
- local octave = math.ceil(note1/12)
- local note2 = (note1 - 1)%12 + 1
- if IsBlack(note1) then
- print('hit')
- --note1(1-61), position x, position y, position z, orientation x, orientation y, orientation z, time
- else
- AnimateKey(note1,0,.06,0,-6,0,0,.15)
- --note1(1-61), position x, position y, position z, orientation x, orientation y, orientation z, time
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement