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)
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
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.
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()
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.