✓ Accepted answer
You can't just make up random pieces of text and assume they'll do what you want. They way you have it set up on line 13, Onclick is nothing more than a variable. There is nothing special about the words Onclick.
To make a part clickable, first you have to put a ClickDetector in it, then use the MouseClick event of the ClickDetector. An event is basically something that prevents a specific code block from running until its conditions are met. In this case, we want to prevent code from running until the MouseClick event is fired.
*I'll assume both the Script and the ClickDetector are direct children of the Part. *
To do this, we first put an area of code inside a function. We do this because functions do not run until they are called. Regular code blocks run as soon as the game starts, but functions don't run until we make them run.
function playSound()
local s = Instance.new("Sound")
s.Name = "Sound"
s.SoundId = "http://www.roblox.com/asset/?id=130766856"
s.Volume = 7.25
s.Looped = false
s.Archivable = false
s.Parent = game.Workspace
end
As is stands, this code will not run because we are not doing anything to make it run. This is good, because we want to make it so that this function will execute every time the MouseClick event is fired. We do this with what is commonly called a connection line, we must connect the function to the MouseClick event.
function playSound()
local s = Instance.new("Sound")
s.Name = "Sound"
s.SoundId = "http://www.roblox.com/asset/?id=130766856"
s.Volume = 7.25
s.Looped = false
s.Archivable = false
s.Parent = game.Workspace
end
script.Parent.ClickDetector.MouseClick:connect(playSound)
3 comments
How was I supposed to know he/she was using a ClickDetector? I answered this earlier when he/she didn't explain it was a ClickDetector. I thought it was a Gui.
There is no need to downvote me.
The person posted this an hour ago, you put your question 55 minutes ago. Please read the question throughly in the future, for the asker explains a ClickDetector is being used.