I need a script or I need help how to make a script and a brick with sound so like if a object in the game hits the brick it makes that sound... how to do that?
The code below is how to do so, explanations will come after I type the code.
local part = script.Parent local sound = part:WaitForChild("Fire") local debounce = false part.Touched:connect(function(part) if part and part.Parent:FindFirstChild("Humanoid") then if debounce == false then debounce = true sound:Play() wait(sound.TimeLength) debounce = false end end end)
The code above first states 3 variables: part, sound, and debounce. Part is the parent of the script, which is the part the player touches. Sound is the sound that is going to be played. Put the sound inside the part. For sound, it says "part:WaitForChild("Fire")" Change "Fire" with the name of the part. For example, if the sound was named "Fly" then it would be "part:WaitForChild("Fly")". The variable debounce is a Boolean value(values that are set to true or false), this will be used in the function.
On the 6th line it says part.Touched:connect(function(part). This means the function will start when the part is touched. We then check to make sure it only works if a player touches it. We do this by saying "if part and part.Parent:FindFirstChild("Humanoid") then". We then use the debounce, to make sure the same sound will not play 2 times, at the same time. By saying "sound:Play()" we are playing the sound. We then say "wait(sound.TimeLength)", followed by "debounce = false". What this does it wait until the sound is finished playing, then allows it to be played again.
Hope this helped :)
http://wiki.roblox.com/index.php?title=API:Class/BasePart/Touched
This will help you learn.