Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Disable sound playing on equip (tool)?

Hello, I have a script inside of a tool that plays a song when it is pulled out, however once it is put away the music still plays and keeps playing in the area where the tool was put away. How can I stop the music from playing after its been de-equipped? Here's the script, the sound is in the handle

local Tool = script.Parent;
enabled = true
function onActivated()
if not enabled  then
return
end
enabled = false
local h = Tool.Parent:FindFirstChild("Humanoid")
if (h ~= nil) then
if (h.MaxHealth > h.Health + 0) then
h.Health = h.Health + 0
else	
h.Health = h.MaxHealth
end
end
enabled = true
end
function onEquipped()
wait(0.1)
Tool.Handle.EquipSound:play()
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)

1 answer

✓ Accepted answer

So your solution is pretty simple. In my code, I've added a function where it stops the sound when the tool is unequipped

local Tool = script.Parent
enabled = true
function onActivated()
if not enabled  then
return
end
enabled = false
local h = Tool.Parent:FindFirstChild("Humanoid")
if (h ~= nil) then
if (h.MaxHealth > h.Health + 0) then
h.Health = h.Health + 0
else    
h.Health = h.MaxHealth
end
end
enabled = true
end
function onEquipped()
wait(0.1)
Tool.Handle.EquipSound:play()
end
function stop()
Tool.Handle.EquipSond:Stop()
end
script.Parent.Activated:connect(onActivated)
script.Parent.Equipped:connect(onEquipped)
script.Parent.Unequipped:connect(stop)

2 comments

0

Thanks

0

It still plays after putting it away

This discussion is preserved as it was. New answers, comments, and votes are closed.