Make DoorOpen and Close Sound play locally

Hello,
So I have this ProximityPrompt door here, and inside of the script, code to make sounds play once the player opens the door. The only issue is that it plays for the entire Server, and not just for the person that is opening the door.

Here’s the script:

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

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

function OpenDoor()
	local sound = script.DoorOpen
	local closingsound = script.DoorClose
	if opened == false then
		opened = true
		sound:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(4.3), 0))
			wait()
		end
	else
		opened = false
		closingsound:Play()
		for i = 1, 21 do
			script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-4.3), 0))
			wait()
		end
	end
end
Promt.Triggered:Connect(function(Players)
	OpenDoor()
end)
script.Parent.Door1.ProximityPrompt.Triggered:Connect(OpenDoor)

Here’s where how it’s constructed:

Thank you for any tips

PS: The door has to open visibly for all players, only the player that opened the door should be able to hear the sound though

Considering the door is a server created object, you should be able to access the sounds from a client script.

The problem is to know ‘when’ to play the sound and when to stop it.

You can use a RemoteEvent to tell the client to play a sound, and even give it the Instaces of the sounds to play

So maybe just make a local script called ‘sound player’ and it looks for events from the server, with a remote event, that tells it to either play a sound or stop a sound, and the instances of the sounds. Keep the playing sounds in a table keyed by the sound id, and so you can easily find the sound to stop it playing

Then have the door fire the events to the client

1 Like

The sound is not looped, hence it shouldn’t be too big of an issue to stop the sound

Wait, how do I make the sounds play inside of a part? So it actually sounds like the door opens, if you know what I mean? Do I just have to define where the sound is?

When a sound’s parent is a Part, then it’ll play on that part. If it’s in somewhere like a Script, then it’ll play globally.
What you’re gonna want to do is put the sounds in one of the parts in the door (the door part that moves would be more suitable), then play the sounds, since that’s the easiest solution.

2 Likes

As long as an instance (the sound object) is parented somewhere under workspace (such as inside the door) you can send it by reference through a remote event.

So when you play it, it will play in the part its a child of, but only on the client actually calling the :Play()

1 Like

Isn’t the sound parented and played from a part in the workspace heard by everyone close to it when :Play() is called?
The script or remote calls for it, but the sound is still in the part.

1 Like

Publish this somewhere, and get in with a friend, and see if the tiny bell only is heard on the client of who clicked it.

SoundsTest.rbxl (54.6 KB)

1 Like