Problem with sound hearing for everyone please help

I am trying to make block when you touch it makes sound it works now fine but the sound is hearing for evryone. ( so everyone can hear same voice , BUT I DONT TO DO THAT:
( I WANT ONLY THE PLAYER WHO TOUCHES THE BLOCK HEARS THE SOUND)
CAn someone example or make the code right THANKS!

local played = false
script.Parent.Touched:Connect(function(hit)
	if played == false then
		workspace.SoundLibrary.Scream:Play() --these are Sounds and The Folder in the workspace
		played = true
		wait (5) 
		played = false
	end
end)

2 Likes

Didn’t you made this post already. I already gave you the solution. Use a remote event, let a client listens to it, then just spawn the sound locally, not on the server.

Is the script local? It may be the issue however that coincidentally may not be the solution.

Please give me some screenshots or code I am not good in english!

Its normal script inside the block

Make it local script, just realized you’re trying to make it so the start user only hears it, in this case the sound only plays for one local.

So will I just make the same script inside the block and change it to local script and put it inside the same block?

You could try it, who knows? It may fix your issue.

I will try that maybe it works

Use a localscript in client side, and have a reference to the part you to connect the .Touched to, and then on Touch check if the hit part’s parent is a player, if yes then play it. Otherwise it will be played on anything that touches it.

Also note If you don’t have RespectFilteringEnabled set to true, then client sounds replicate to the server.

You can pretty much refactor your current code to work accordingly, also localscript must be placed in StarterGui / StarterPack or other places where they run, not workspace, they won’t run there unless parented to character.

local Sound = --Reference To Sound
local Part = --Reference To part

Part.Touched:Connect(function(hit)
   local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Get player if there 
  
   if player then
      Sound:Play() --Play Sound if player had touched.
   end
end)

That is just an example, you can take the idea and move on to adding debounce and stuff that you want.


1 Like

It makes error sorry it not work.

There is no issue with their code so if it errors make sure you typed it correctly and declared the variables.(also would be helpful to know the error)

Have you actually changed the reference and tried to implement it according to your needs? Or did you just copy paste? If you just copy pasted, read my post more carefully.

Also what is the error, if you post it here, its helpful.

1 Like

Will i do it like this
local Sound = --Reference To Sound
local Part = --Reference To part

Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Get player if there

if player script.Parent.Touched:Connect(function(hit)
then
Sound:Play() --Play Sound if player had touched.
end
end)

You need to change local sound to wherever your sound is and local part to wherever your part is.

BASED ON PREVIOUS CODE

local sound = game.Workspace.SoundLibrary.Scream
and the part would be
local part = game.Workspace.wherever your part is.

I don’t know how many times I have said this to people today, but that was meant to be an example if you had read my post. Then its also your duty to read the comments and use some logic to implement it with the basic idea.

so basically Sound Refers to the Sound variable, Part Refers to the Part you want to connect the event to. Also you should add a debounce in the event.

local sound = game.Workspace.SoundLibrary.Scream
and the part would be
local part = game.Workspace.Coin
Part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Get player if there

if player script.Parent.Touched:Connect(function(hit)
then
Sound:Play() --Play Sound if player had touched.
end
end)

A. I would recommend learning some lua before continuing programming but the code would be

local sound = game.Workspace.SoundLibrary.Scream
local part = game.Workspace.Coin
Part.Touched:Connect(function(hit)
     local player = game.Players:GetPlayerFromCharacter(hit.Parent) --Get player if there

     if player then
          Sound:Play() --Play Sound if player had touched.
     end
end)

It gives error in the **

script

**.Parent.Touched:connect(function(hit)

How do you think we’re supposed to know what is causing the problem, unless you give your output error log. And it also doesn’t seem like you have followed up with the code provided to you, as it just seems like you’re using your original code.

1 Like