I need help with making a door opening sound play correctly.
It does work… sort of.
It only plays the sound for one select door and not the door you opened.
The reason for this is that I made it look for a door under the correct name but since every door needs the same name it won’t work correctly.
It just plays the sound for one select door constantly and never plays it for the door you opened.
Code:
local ServerScriptService = game:GetService("ServerScriptService")
local CollectionService = game:GetService("CollectionService")
local Functions = ServerScriptService:WaitForChild("Functions")
local sound = game.Workspace.Map.Door.Door.Prompt.Dooropen
local Connection = {}
function applyCode(Inst)
if not Inst:IsA("Model") then return end
Connection[Inst] = {}
local Goal = {
Open = {
Left = Inst:WaitForChild("Goal"):WaitForChild("Open"):WaitForChild("Left"),
Right = Inst:WaitForChild("Goal"):WaitForChild("Open"):WaitForChild("Right")
},
Close = {
Left = Inst:WaitForChild("Goal"):WaitForChild("Close"):WaitForChild("Left"),
Right = Inst:WaitForChild("Goal"):WaitForChild("Close"):WaitForChild("Right")
}
}
Inst:WaitForChild("LeftSide").CFrame = Goal[Inst:GetAttribute("Closed") and "Close" or "Open"].Left.CFrame
Inst:WaitForChild("RightSide").CFrame = Goal[Inst:GetAttribute("Closed") and "Close" or "Open"].Right.CFrame
local ProximityPrompt = Instance.new("ProximityPrompt")
ProximityPrompt.ObjectText = "Door"
ProximityPrompt.ActionText = Inst:GetAttribute("Closed") and "Open" or "Close"
ProximityPrompt.RequiresLineOfSight = false
ProximityPrompt.Parent = Inst:WaitForChild("Prompt")
table.insert(Connection[Inst], ProximityPrompt.Triggered:Connect(function()
if Inst:GetAttribute("Disabled") then return end
Inst:SetAttribute("Closed", not Inst:GetAttribute("Closed"))
sound:Play()
ProximityPrompt.Enabled = false
ProximityPrompt.ActionText = Inst:GetAttribute("Closed") and "Open" or "Close"
Functions:WaitForChild("ClientTween"):Invoke(Inst:WaitForChild("LeftSide"), {2, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out}, {
CFrame = Goal[Inst:GetAttribute("Closed") and "Close" or "Open"].Left.CFrame
})
Functions:WaitForChild("ClientTween"):Invoke(Inst:WaitForChild("RightSide"), {2, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out}, {
CFrame = Goal[Inst:GetAttribute("Closed") and "Close" or "Open"].Right.CFrame
})
task.wait(2.5)
ProximityPrompt.Enabled = true
end))
end
task.spawn(function()
local Tagged = CollectionService:GetTagged("Door")
for count=1, #Tagged do
local Inst = Tagged[count]
task.spawn(function()
applyCode(Inst)
end)
end
end)
CollectionService:GetInstanceAddedSignal("Door"):Connect(function(Inst)
task.spawn(function()
applyCode(Inst)
end)
end)
CollectionService:GetInstanceRemovedSignal("Door"):Connect(function(Inst)
if not Connection[Inst] then return end
for count=1, #Connection[Inst] do
local con = Connection[count]
con:Disconnect()
end
Connection[Inst] = nil
end)
Anyway to get this to play for the door you opened?