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.

local Sword = script.Parent

Sword.Equipped:connect(function() – Fires when equipped
Sword.Handle.EquipSound:Play() – Plays equip sound
end)

Sword.Activated:connect(function() – Fires when clicked while equipped
Sword.Handle.SlashSound:Play() --Plays slash sound
end)

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()

local tool = script.Parent --The tool
local sound = script:WaitForChild('Sound') --Change to the sounds location

tool.Activated:Connect(function() --Fires when the tool is activated
    sound:Play() --plays the sound
end)

tool.Equipped:Connect(function() --Fires when the tool is Equipped
    sound:Play() --plays the sound
end)

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