I've made a door that can open and close with a button you click on the side and I don't know how to add audio to it so that when it opens said audio will play and when it closes a different audio plays. I have three scripts but each script is the same just going to a different part of the door like top part goes up and bottom part goes down
Script 1. Top goes up
db = false
door = false
script.Parent.DoorButton.ClickDetector.MouseClick:connect(function()
if not db then db = true
if not door then door = true
for i=0,60 do
script.Parent.Doortop1.CFrame = script.Parent.Doortop1.CFrame - Vector3.new(0,-0.1,0)
wait()
end
script.Parent.Doortop1.CFrame = script.Parent.Doortop1.CFrame - Vector3.new(0,0.2,0)
db = false
elseif door then door = false
for i=0,60 do
script.Parent.Doortop1.CFrame = script.Parent.Doortop1.CFrame + Vector3.new(0,-0.1,0)
wait()
end
script.Parent.Doortop1.CFrame = script.Parent.Doortop1.CFrame + Vector3.new(0,0.2,0)
db = false
end
end
end)`
Script 2. Bottom goes down
db = false
door = false
script.Parent.DoorButton.ClickDetector.MouseClick:connect(function()
if not db then db = true
if not door then door = true
for i=0,17 do
script.Parent.Doorbottom.CFrame = script.Parent.Doorbottom.CFrame - Vector3.new(0,0.1,0)
wait()
end
script.Parent.Doorbottom.CFrame = script.Parent.Doorbottom.CFrame - Vector3.new(0,0.2,0)
db = false
elseif door then door = false
for i=0,17 do
script.Parent.Doorbottom.CFrame = script.Parent.Doorbottom.CFrame + Vector3.new(0,0.1,0)
wait()
end
script.Parent.Doorbottom.CFrame = script.Parent.Doorbottom.CFrame + Vector3.new(0,0.2,0)
db = false
end
end
end)

1 comment
You could create a sound that is a child of the scripts parent and call on it with script.Parent.SoundName:Play()