I am just starting on scripting and I was wondering how to make this. So what I do is just walk up to the part, click it and it makes a noise. How do I do this?
COMMUNITY QUESTION
How do I make a part that makes a sound when you click it?
2 answers
What you'll need for this is a ClickDetector, which will fire an event when the player clicks on it. Simply connect a function to the event, and the function will be ran whenever the event is fired. Also take note of the method named FindFirstChildOfClass, which finds the first child of the given type, in this case Sound. After we've gotten the sound, we can simply call its Play method whenever we want to play it.
--This code is in a Script, which is in the desired part.
local clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = script.Parent
local sound = script.Parent:FindFirstChildOfClass("Sound")
clickDetector.MouseClick:Connect(function()
sound:Play()
end)
put a click detector object inside of the part and use the click detector clicked event
--function that gets called whenever the clickdetector gets clicked:
game.Workspace.PartNameHere.ClickDetector.MouseClick:Connect(function()
game.Workspace.Sound:Play() --play sound
end)
Here's a tutorial about events: https://www.youtube.com/watch?v=oAnWzxol4e8 I'd recommend watching the whole series since you're knew. It's a good resource.
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
How do i make it play the sound i want it to play?
If you have the sound in the explorer, simply child it to the part (drop the sound on top of it), and the script will find it.
It's not working... am I just not seeing something here?
Have you made sure the sound is a child of the part? Can you send a pic?