How do I add opening and closing sounds to my door? (UNSOLVED)

Title says it all.

  1. I want my door to play sounds when opening, and closing.

  2. I have a script inside of my Door (to open it), and I do not know how to implement this myself.

  3. I do not know how to script, and I unfortunately I am too busy/occupied to learn Scripting, so I don’t know how to do this myself.

I have a ProximityPrompt in the Model, and a loose script in the model, for the door (The Door works fine)

local Hinge = script.Parent.PrimaryPart
local opened = false

local Promt = script.Parent:WaitForChild("ProximityPrompt")

function OpenDoor()
	if opened == false then
		opened = true
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(5), 0))
			wait()
		end
	else
		opened = false
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-5), 0))
			wait()
		end
	end
end
Promt.Triggered:Connect(function(Players)
	OpenDoor()
end)
script.Parent.Door1.ProxomityPrompt.Triggered:Connect(OpenDoor)

Lastly,
Thanks for anyone that could figure this out, or help me with this
I appreciate it!

Sincerely,
Switched.

2 Likes

local Hinge = script.Parent.PrimaryPart
local opened = false

local Promt = script.Parent:WaitForChild(“ProximityPrompt”)

function OpenDoor()
local sound = put the sound instance here
local closingsound = put the closing sound here
if opened == false then
opened = true
sound:Play()
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrameCFrame.Angles(0, math.rad(5), 0))
wait()
end
else
opened = false
closingsound:Play()
for i = 1, 21 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame
CFrame.Angles(0, math.rad(-5), 0))
wait()
end
end
end
Promt.Triggered:Connect(function(Players)
OpenDoor()
end)
script.Parent.Door1.ProxomityPrompt.Triggered:Connect(OpenDoor)

2 Likes

Thank you, I’m sorry, as I said I suck at scripting, so where should I put the sounds? In the model, or the script?

1 Like

Place both sounds in the script, then put this into the opening sound variable:

script.YourOpeningSoundName

Then put this in your closing sound variable:

script.YourClosingSoundName

Remember to change “YourOpeningSoundName” or “YourClosingSoundName” to the name of the sounds.

2 Likes

Okay thank you, this makes a lot of things easier.

1 Like

Hey, apologies, ONCE AGAIN… (I’m terribly sorry)

I looked at the script again, and noticed it’s throwing out some red lines, I’m not sure if it’s errors, or just some reminders of some sorts? I don’t know, anyways, here they are:

UPDATE: The door won’t open anymore :confused:

1 Like

That’s because the variable is empty, put the sound instances into the variables, for instance put “script.WhateverYourSoundName” onto the opening sound variable and put “script.WhateverYourClosingSoundName” onto the closing sound variable

2 Likes

I did that, and it’s still underlining it, and as mentioned below the picture, the door won’t open anymore:

Error from output:


Script:

1 Like

Retype the line. This is because the encoding is wrong.

2 Likes

You misspelled ProximityPrompt where the red line is

2 Likes

Right, I fixed the typo, but it’s still underlining it.

1 Like

Oh I know. Retype the thing in the parantheses () because the quotation marks are from a different keyboard so studio might not recognize them

2 Likes

That’s because the encoding is wrong. The quotes are supposed to be like this: ", not this:”

2 Likes

Oh, gotchaa! Now it turned green, I suppose it’s working.

Test it, it will work if you did it correct.

Yeah, the sounds play now, but the door won’t budge a a bit-

Are there errors in the output? Or any more underlines?

1 Like

CFrameCFrame is not a valid member of Part “Workspace.Door1.Hinge”

Did the door open before? Or did it stop working after

1 Like

You typed CFrame twice after hinge (both the lines after for i = 1, 21 do)
image

1 Like