Sound played at both opening and closing of door

This script should play a short simple sound when the door is clicked and play another sound when it closes 5 seconds later, it doesnt work

local model = script.Parent.Parent
local clickdetector = script.Parent
local open = workspace.Doorsclosed.Open
local close = workspace.Doorsclosed.Close

local set = true

if not open.IsLoaded then
	open.Loaded:wait()
end

if not close.IsLoaded then
	close.Loaded:wait()
end

for _,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				Open:play()
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
				Close:play()
			end
			if (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end

	if v:IsA("WedgePart") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
			end
			if (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end
end
2 Likes

No errors? If not then Iā€™d assume it might have something to do with the Sound instances themselves, perhaps volume or RollOffMax/MinDistance.

1 Like

idk if its important but these are underlined
image

1 Like

What does it say when you hover over them?

FIGURED IT OUT!

Just uncapitalise the Open and Close.

this

image

its not underlined anymore but it doesnt play the sounds

local model = script.Parent.Parent
local clickdetector = script.Parent
local open = workspace.Doorsclosed.Open
local close = workspace.Doorsclosed.Close

local set = true

if not open.IsLoaded then
	open.Loaded:wait()
end

if not close.IsLoaded then
	close.Loaded:wait()
end

for _,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				open:Play()
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
				close:Play()
			end
			if (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end

	if v:IsA("WedgePart") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
			end
			if (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end
end

You have to capitalize the Play.

Strange. I tried without caps like 10 minutes ago and it worked fine.

Could you open the output, and show us anything that appears when you open or close the door?
image
^ How to find output in case you need

both with or without caps dont work for me

1 Like

nothing shows up in the output when i click it, it doesnt even open or close anymore its broken now

What are the sound names? open and closed?

What is the purpose of the loaded and isloaded at the start?

no idea, i searched help about this and found the same thing in their scripts, and yes those are the names of the sound

Can you show us Output please?

theres nothing in the output when i click the door, it doesnt even open anymore with the new scripts from above

You should use else

if (set == true) then
			v.Transparency = 1
			v.CanCollide = false
			Open:play()
			wait(5)
			set = false
			v.Transparency = 0
			v.CanCollide = true
			Close:play()
		end
		if (set == false) then
			v.Transparency = 0
			v.CanCollide = true

			set = true
		end

it doesnt work still

local model = script.Parent.Parent
local clickdetector = script.Parent
local open = workspace.Doorsclosed.Open
local close = workspace.Doorsclosed.Close

local set = true

if not open.IsLoaded then
	open.Loaded:wait()
end

if not close.IsLoaded then
	close.Loaded:wait()
end

for _,v in pairs(model:GetChildren()) do
	if v:IsA("Part") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				open:Play()
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
				close:Play()
			
			elseif (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end

	if v:IsA("WedgePart") then
		clickdetector.MouseClick:Connect(function()
			if (set == true) then
				v.Transparency = 1
				v.CanCollide = false
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
			
			elseif (set == false) then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end
		end)
	end
end
if set == true then
				v.Transparency = 1
				v.CanCollide = false
				open:Play()
				wait(5)
				set = false
				v.Transparency = 0
				v.CanCollide = true
				close:Play()
			
			elseif set == false then
				v.Transparency = 0
				v.CanCollide = true

				set = true
			end

Remove ( )

Are you trying to achieve where you open the door and the open sound plays and after 5 seconds, the door closes with the close sound?

Your problem must be that the same sound plays on opening and closing, right? Please tell which sound is playing on both opening and closing of the door.

1 Like