Hello there, I recently made a custom sword, with on-key animations, and everything works except for the sound, my sword only functions when you press certain keys, and the sound only seems to play if I click.
Is there a way for my sword to have sound?
It also may or may not be a problem that my Handle is a MeshPart.
What my sword look’s like.
Where’s the sound object?
Providing code would also be helpful.
Sorry, should’ve done that earlier.
This is the Handle.
And this is the code in it
local Sword = script.Parent
Sword.Equipped:connect(function() – Fires when equipped
Sword.Handle.EquipSound:Play() – Plays equip sound
Sword.Activated:connect(function() – Fires when clicked while equipped
Sword.Handle.SlashSound:Play() --Plays slash sound
Well for the function bound to Equipped, it’s try to find an object called ‘EquipSound’ in Handle. As we can see, there is not a sound there called EquipSound – but there is a sound called ‘Unsheath’.
Secondly the function bound to Activated also would not work because there is not an object called ‘SlashShound’ in Handle. Same deal - you are probably looking for ‘Slash’ instead.
:connect() is deprecated, use
Sword.Handle.Unshealth:Play() -- note that both the object's name and the spelling on this line is incorrect - it's 'unsheath' not 'unshealth'
Sorry about the connect thing; I’m used to using :connect() before it was deprecated. I should have fixed that before posting the code sample on his previous post.
Hey, it worked but it doesn’t play sound when I hit a key (When a key is hit that is when an animation for the sword is played) It’ll only play sound when I click, and nothing happens when I click.
Well the issue here is that you haven’t put sound into the function handles the animations.
Same thing with you’re animations - you’re using animations on a key press, and sounds on a click. Obviously they won’t work together, as they’re separated. If you want them both on a click, you’d put them together:
-- animation here
And vice versa for on a key press.
Sword.Activated fires whenever you click while having the tool equipped. If you want it to play with the animations, it needs to be of the same event as the animations. You may have to do it from the localscript if that is where you are playing the animations from.
Thank you that is exactly what I was missing.