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

How do i make a tool play a sound when clicked?

Asked by 4 years ago

I made different tools in my 3 months, what i dont know is how a tool plays a sound when it is clicked. I am currently working on a simulator and i want to know how to code. ive had several local scripts but they all dont work.

1local Sword = script.Parent
2 
3Sword.Equipped:connect(function() – Fires when equipped
4Sword.Handle.EquipSound:Play() – Plays equip sound
5end)
6 
7Sword.Activated:connect(function() – Fires when clicked while equipped
8Sword.Handle.SlashSound:Play() --Plays slash sound
9end)
1
The script is probably not working because of the 2 lines "– Fires when equipped" and "– Plays equip sound" instead use -- instead of an endash holamii2 45 — 4y
0
oh Noxcitrus 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

my only guess is that the sound isnt loaded, the sound was removed, or the sound on your pc/in your properties is set to 0, the below script worked for me so u should probs check your sound and also add a :WaitForChild()

01local tool = script.Parent --The tool
02local sound = script:WaitForChild('Sound') --Change to the sounds location
03 
04tool.Activated:Connect(function() --Fires when the tool is activated
05    sound:Play() --plays the sound
06end)
07 
08tool.Equipped:Connect(function() --Fires when the tool is Equipped
09    sound:Play() --plays the sound
10end)

if i fixed your problem please accept my answer! if theres any issues ping me in the community chat and i'll be happy to help!

0
i forgot to rename the sound, Thanks! Noxcitrus 2 — 4y
0
np ImUID3558 20 — 4y
Ad
Log in to vote
-2
Answered by 4 years ago

2 things:

1) Make a variable for each sound. 2) Use :Connect!

That's all, any errors in the output? Also a very useful tip: Use Print() to detect if a function is functioning :)

Answer this question