4

# How do I make a sound play when a brick is clicked, and play for only the person who clicked it?

So I'm fairly sure I know how to make the sound play when a player clicks a brick. I think it would be a brick with a click detector in it, and then the script would be:

script.Parent:Play()



At least I think so. But the real problem, is how would I make it so only the player who clicked it heard the sound? Would I just put the sound in the PlayerGui? Or would it be something different?

 I'm using:

script.Parent:Play()


Would I use:

script.Parent:Play(NameOfSound)


? Or do I need a whole new code, cause if so I have no idea what it would be.

0
Sublimus 992
8 years ago

Yes, just place the sound in the PlayerGui, that will make it play locally.

0
Awesome. Thanks again huner :D Tallestmidget7 95 — 8y
0
No problem, be sure to rep up! Sublimus 992 — 8y
0
Oh, I just thought of something though. I made it so that a sound plays for a player when they join. Plus I wanted multiple sound click bricks. How can I make the scripts know which sound to play? Tallestmidget7 95 — 8y
0
Use the sounds name, so if you put all the sounds in the StarterGui, so that when they join they are already in the PlayerGui, you can just play by the sounds name. Sublimus 992 — 8y
0
Hate to bug you again with this, but what do you mean? How could I define the name of the sound, and then make the script recognize it? Would I rename the sound in the PlayerGui, and then in the () marks in the script, have the name of the sound? Tallestmidget7 95 — 8y
0
Here, edit the post with what code you are trying to use. Sublimus 992 — 8y
0
Mmk, edited. Tallestmidget7 95 — 8y
2
Dummiez 360
8 years ago

Thanks to the use of Click Detectors! You can create a sound object within a brick and send it into the Player's PlayerGui to play the sound.

-- This script goes into a ClickDetector within a part.

local function onMouseClick(Player)
if not Player.PlayerGui:findFirstChild("ClickAudio") then
local ls = Instance.new("Sound")
local length = 1 -- How long the sound plays before removed.

ls.SoundId = "http://www.roblox.com/asset/?id=" -- Audio id here.
ls.Name = "ClickAudio"
ls.Volume = 0.5
ls.Pitch = 1
ls.Parent = Player.PlayerGui
ls:Play()

end
end
script.Parent.MouseClick:connect(onMouseClick)

0
Awesome! Seems to be working. Tallestmidget7 95 — 8y
0
No problem! :) Dummiez 360 — 8y
0
One problem, the weapons keep respawning. Like endlessly. I only want it to respawn once the one that is there has been taken. Tallestmidget7 95 — 8y
0
you never mentioned anything about weapons. Dummiez 360 — 8y
0
Sorry. Being a tard. Posted it on the wrong question. Tallestmidget7 95 — 8y
0
yurhomi10 192
8 years ago

Try playing local sounds.

To do this, you insert the sound object in the player's playergui, so sounds aren't played globally.