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

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

Asked by 10 years ago

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

Log in to vote
0
Answered by
Sublimus 992 Moderation Voter
10 years ago

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

0
Awesome. Thanks again huner :D Tallestmidget7 95 — 10y
0
No problem, be sure to rep up! Sublimus 992 — 10y
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 — 10y
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 — 10y
View all comments (3 more)
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 — 10y
0
Here, edit the post with what code you are trying to use. Sublimus 992 — 10y
0
Mmk, edited. Tallestmidget7 95 — 10y
Ad
Log in to vote
2
Answered by
Dummiez 360 Moderation Voter
10 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()

        game:GetService("Debris"):AddItem(ls, length)
    end
end
script.Parent.MouseClick:connect(onMouseClick)
0
Awesome! Seems to be working. Tallestmidget7 95 — 10y
0
No problem! :) Dummiez 360 — 10y
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 — 10y
0
you never mentioned anything about weapons. Dummiez 360 — 10y
0
Sorry. Being a tard. Posted it on the wrong question. Tallestmidget7 95 — 10y
Log in to vote
0
Answered by
yurhomi10 192
10 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.

Log in to vote
0
Answered by 10 years ago

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

Answer this question