Hey, guys! I'm here due to my script not being able to work. The piano is supposed to play a sound (note) when you press certain keys on your keyboard but as you can see, it is not working. Please help because I have no clue why this isn't working.
Here are my scripts.
Normal script:
wait(5)
local KeyTool = script["PianoPlayer V1.1"]:Clone()
script["PianoPlayer V1.1"]:Remove()
position = script.Parent.Archive.Position
local frame = Instance.new("CFrameValue")
frame.Name = "OriginCFrame"
frame.Value = script.Parent.Archive.CFrame
frame.Parent = script.Parent
local object = Instance.new("ObjectValue")
object.Value = script.Parent.Parent.Parent
seat = script.Parent.Seat
function onSitUp(child, hopper, piano, object)
if child.Parent == nil then
hopper:Remove()
object:Remove()
--script.Parent.Parent.Parent = game.Workspace
end
end
function onChildAdded(part)
if part.className == "Weld" then
local torso = part.Part1
if torso ~= nil then
local parent = torso.Parent
--[[if parent ~= nil then
script.Parent.Parent.Parent = parent
end]]
local char = torso.Parent
local player = game.Players:GetPlayerFromCharacter(char)
if player ~= nil then
local hopper = KeyTool:clone()
hopper.Parent = player.Backpack
local object = script["Instrument"]:clone()
object.Value = script.Parent.Parent
object.Parent = char
part.AncestryChanged:connect(function(child) onSitUp(child, hopper, script.Parent.Parent, object) end)
end
end
end
end
seat.ChildAdded:connect(onChildAdded)
seat.BrickColor = BrickColor.new("Really black")
Main Script:
bin=script.Parent
function findPiano(player)
local list = player.Character:GetChildren()
for x = 1, #list do
if (list[x].Name == "Instrument") then
local weld = list[x].Value:FindFirstChild("Parts"):FindFirstChild("Seat"):FindFirstChild("SeatWeld")
if (weld ~= nil) and (weld.Part1 == player.Character:FindFirstChild("Torso")) then
return list[x].Value
end
end
end
-- return nil
end
function onSelected(mouse)
mouse.Icon = "rbxasset://textures\\GunCursor.png"
mouse.KeyDown:connect(onKeyDown)
end
function onKeyDown(key)
if (key~=nil) then
key = key:lower()
local piano = findPiano(script.Parent.Parent.Parent)
if (piano==nil) then return end
parts = piano.Parts
local archive = piano.Parts.Archive
if (key=="a") then
archive:findFirstChild("0").Run.Value = true
end
if (key=="w") then
archive:findFirstChild("0s").Run.Value = true
end
if (key=="s") then
archive:findFirstChild("1").Run.Value = true
end
if (key=="e") then
archive:findFirstChild("2b").Run.Value = true
end
if (key=="d") then
archive:findFirstChild("3").Run.Value = true
end
if (key=="f") then
archive:findFirstChild("4").Run.Value = true
end
if (key=="t") then
archive:findFirstChild("4s").Run.Value = true
end
if (key=="g") then
archive:findFirstChild("5").Run.Value = true
end
if (key=="y") then
archive:findFirstChild("5s").Run.Value = true
end
if (key=="h") then
archive:findFirstChild("6").Run.Value = true
end
if (key=="u") then
archive:findFirstChild("6s").Run.Value = true
end
if (key=="j") then
archive:findFirstChild("7").Run.Value = true
end
if (key=="z") then
archive:findFirstChild("8").Run.Value = true
end
if (key=="x") then
archive:findFirstChild("8s").Run.Value = true
end
if (key=="c") then
archive:findFirstChild("9").Run.Value = true
end
if (key=="v") then
archive:findFirstChild("9s").Run.Value = true
end
if (key=="b") then
archive:findFirstChild("10").Run.Value = true
end
if (key=="n") then
archive:findFirstChild("11").Run.Value = true
end
if (key=="m") then
archive:findFirstChild("11s").Run.Value = true
end
end
end
bin.Selected:connect(onSelected)
Lighting script:
script.Parent.Parent = game:service("Lighting")
script.Parent = nil
Sound Script:
--ToolSoundScript V1.2
--funtimecameron886
wait(2)
local Sound = script.Parent --Defines Sound
local Bool = Sound.Run --BoolValue activated by outside script to request sound
function Play()
wait()
if Bool.Value == true then
Sound:Play() --Plays the sound
wait()
Bool.Value = false
end
end
Bool.Changed:connect(Play)
Hope you guys know how to solve this!

1 comment
Why are you using lighting? Can you privede some more infor about what is not working, e.g. add in some prints so we know what is running and what is not running.