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