Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to add sound when opening and closing door?

Hi, im trying to find out how to add sound to my opening and closing door script but im a bit confused on where to put it.

open = false

door1 = script.Parent.Parent.Parent.Door1

door2 = script.Parent.Parent.Parent.Door2

local TweenService = game:GetService("TweenService")

local part = script.Parent

local tweenInfo = TweenInfo.new(2,Enum.EasingStyle.Linear,Enum.EasingDirection.Out,0,false,0)

local Door1Open = {CFrame = door1.CFrame + door1.CFrame.lookVector * 7}

local Door2Open = {CFrame = door2.CFrame + door2.CFrame.lookVector * 7}

local Door1Close = {CFrame = door1.CFrame }

local Door2Close = {CFrame = door2.CFrame }

local Open1 = TweenService:Create(door1,tweenInfo,Door1Open)

local Open2 = TweenService:Create(door2,tweenInfo,Door2Open)

local Close1 = TweenService:Create(door1,tweenInfo,Door1Close)

local Close2 = TweenService:Create(door2,tweenInfo,Door2Close)

script.Parent.MouseClick:connect(function()

if open == false then

Open1:Play()

Open2:Play()

wait(2)

open = true

else

Close1:Play()

Close2:Play()

wait(2)

open = false

end

end)

1 answer

✓ Accepted answer

First, put insert a "Sound" into SoundService. Then find a sound in library > audio, copy and paste the Id of the audio and paste it into the "Sound" in SoundService.

In your script, write:

local Sound = game:GetService("SoundService"):WaitForChild("Sound")

Sound:Play() -- Write this at where you want the sound to play in your script

2 comments

0

but where would this go into the script?

0

Depends on when you want the Sound to play. Maybe you want it to play after "Open2" is played, so you put it after "Open2:Play()" or if you play it before then put the script above "Open1:Play()"

This discussion is preserved as it was. New answers, comments, and votes are closed.