Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to trigger a sound when a player touch a part but only him can hear the sound?

Asked by 5 years ago

I wanted to make a script that run a sound when a player walk on a part so I have made this script :

script.Parent.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Humanoid") then
    script.Parent.Playing = true
    end
end)

This script work but everyone can hear the sound, I wanted to play the sound Locally so i tried to put the exact same code into a LocalScript but now, i can't hear anything !

The script is in the sound and the sound is in a part

Thank you in advance !

3 answers

Log in to vote
0
Answered by 5 years ago

You need a remoteevent (put it in replicatedstorage or something)

script on the part:

script.Parent.Touched:Connect(function(hit)
if hit.Parent.Humanoid then
game.ReplicatedStorage.RemoteEvent:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent),script.Parent)
end
end)

insert a localscript on startergui. script for the local script:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(part)
part.Sound.Playing = true
end)
0
Thank you for your answer @jdm4llfem8 It's working I just need a friend to test if he can hear or not the sound xD Louix27626 83 — 5y
0
If i want to add a debounce where do I add it? Louix27626 83 — 5y
0
im gonna edit the answer so you can see jdm4llfem8 94 — 5y
0
Actually no i cant, but you have to put it on the script, not the local script jdm4llfem8 94 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Put the script inside a local script, inside the startergui. Then refer to is as workspace.(part)

That way only the player that touched it can hear it.

Log in to vote
0
Answered by 5 years ago

@ThePoint13, I took my script, put it into a LocalScript in the StarterGui but where do I put the Sound and do i need to put something in the LocalScript or it can stay empty

Answer this question