Door Sound Plays for Everyone in Server [SOLVED]

Hi there.

I made a door script which works and everything, but when a player opens the door, the sound the door plays, plays for everyone in the server, even if they’re across the map.

How would I make it so that only the player that opened the door can be the only player to hear the door sound or at least have it be a proximity sound so someone that isn’t across the map can’t hear it.

local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorHinge = door.PrimaryPart
local doorOpen = TweenInfo.new()

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-90),0)
})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0),0)
})

local ProximityPrompt = script.Parent.ProximityPrompt
local PromptVanish = ProximityPrompt.Enabled == false
local PromptAppear = ProximityPrompt.Enabled == true

ProximityPrompt.Triggered:Connect(function()
	doorCFrame:Play()
	ProximityPrompt.Enabled = false
	script.Parent.Open:Play()
	wait(0.95) --Door Stays Open this long
	doorCFrameClosed:Play()
	ProximityPrompt.Enabled = true
	wait(1)
	script.Parent.Close:Play()

end)

image

If anyone can help, that would be great.

P.S. Thank you to everyone who replied to the post and helped out. It really means a lot especially because I am a fairly new developer and I’m glad that the DevForum is really helpful and supportive. Thank you.

You could use a remote event and have the sound on the client.

1 Like

How would I do that? Sorry I’m not really familiar with remote events and all.

try changing rolloffmaxdistance of the sound to make it so someone that isn’t across the map can’t hear it.

Capture

1 Like

Just tried it. It doesn’t work at least on my client. Am I the only one that’s supposed to hear it?

script in the door

local TweenService = game:GetService("TweenService")
local door = script.Parent
local doorHinge = door.PrimaryPart
local doorOpen = TweenInfo.new()
local OpenEvent = game.ReplicatedStorage:WaitForChild("OpenEvent")

local doorCFrame = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(-90),0)
})

local doorCFrameClosed = TweenService:Create(doorHinge, doorOpen, {
	CFrame = doorHinge.CFrame * CFrame.Angles(0, math.rad(0),0)
})

local ProximityPrompt = script.Parent.ProximityPrompt
local PromptVanish = ProximityPrompt.Enabled == false
local PromptAppear = ProximityPrompt.Enabled == true

ProximityPrompt.Triggered:Connect(function(Plr)
	doorCFrame:Play()
	ProximityPrompt.Enabled = false
	OpenEvent:FireClient(Plr, script.Parent.Close)

	wait(0.95) --Door Stays Open this long
    doorCFrameClosed:Play()
	ProximityPrompt.Enabled = true
	wait(1)
	OpenEvent:FireClient(Plr, script.Parent.Open)
end)

LocalScript in StarterPlayerScripts

local OpenEvent = game.ReplicatedStorage:WaitForChild("OpenEvent")
OpenEvent.OnClientEvent:Connect(function(Sound)
	local NewSound = script:FindFirstChild(Sound.Name)
	NewSound:Play()
end)

add a copy of the Sound into the local script and then add a remote event into replicated storage and then rename it to OpenEvent

1 Like

ok i figured it out, you might want to parent the sounds to a part in your door (example: Hinge) and then play the sounds that are inside the part, since you have the sounds in the model they will play globally, hope this helps!

2 Likes

Use a RemoteEvent. One example is to put the RemoteEvent into the workspace and link it to the client that way.

1 Like

What about the closing sound? Would I add a different remote event for that and local script?

let me quote what i said earlier

ok i figured it out, you might want to parent the sounds to a part in your door (example: Hinge) and then play the sounds that are inside the part, since you have the sounds in the model they will play globally, hope this helps!

1 Like

add the open and close sound into the local script

Capture

2 Likes

If you wanted, you could pass the same function but with an identifier, marking if it’s open or closed.

2 Likes