Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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?

[Edit] 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.

4 answers

✓ Accepted answer

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

7 comments

0

Awesome. Thanks again huner :D

0

No problem, be sure to rep up!

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?

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.

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?

0

Here, edit the post with what code you are trying to use.

0

Mmk, edited.

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()
		
		game:GetService("Debris"):AddItem(ls, length)
	end
end
script.Parent.MouseClick:connect(onMouseClick)

5 comments

0

Awesome! Seems to be working.

0

No problem! :)

0

One problem, the weapons keep respawning. Like endlessly. I only want it to respawn once the one that is there has been taken.

0

you never mentioned anything about weapons.

0

Sorry. Being a tard. Posted it on the wrong question.

Try playing local sounds.

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

um i may not be a good scripter buttPlayer.PlayerGui:findFirstChild("ClickAudio") then 05 local ls = Instance.new("Sound") 06 local length = 1 -- How long the sound plays before removed. 07

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

15 game:GetService("Debris"):AddItem(ls, length) 16 end 17 end 18 script.Parent.MouseClick:connect(onMouseClick) there

This discussion is preserved as it was. New answers, comments, and votes are closed.