When creating a custom movement system, the default roblox sounds may not suit your own custom animations or the style of game that you’re creating. In these cases, it can be useful to change the default sounds of the character to better fit what you are trying to achieve.
In this tutorial, I will show you how I achieved this for my upcoming game Blox Sprint.
Firstly, to change the default sounds, we must remove the old default sounds. These sounds are located within the HumanoidRootPart
and are only loaded on the client. Each sound has a corresponding name to when it is used as you can see below:
In order to remove these sounds, we can use a simple local script located inside of the character itself. To do this, you need to add a local script inside of StarterCharacterScripts
inside of StarterPlayer
. As shown below:
Try to name it something relevant to what the script is doing such as “JumpSound”.
Next, we can write the code to remove the default sounds. To do this, we can check for the sound and then remove it as shown below:
local Root = script.Parent:WaitForChild("HumanoidRootPart") -- The part the sounds are stored in
local JumpSound = Root:WaitForChild("Jumping", 5) -- The sound that plays when you jump (change the string depending on what you want to remove)
if JumpSound then
JumpSound:Destroy() -- Remove the sound to stop it from playing
end
Next, we can add our new sound. Firstly, add a new Sound instance inside of your script and make sure the SoundId variable is set to the Id of your custom sound. Your explorer window should look something like this:
Next, we can code write the code to play the new sound when needed. Here is an example of how you could code this for a jump:
local Sound = script:WaitForChild("NewJump") -- Your custom sound
local Humanoid = script.Parent:WaitForChild("Humanoid") -- The humanoid of the Character
Humanoid.Jumping:Connect(function(Active) -- The event detecting the jump
if Active == true then -- Checks that it started the jump (not needed for other actions)
Sound:Play() -- Play the sound
end
end)
Now if you test your game, it should work:
You can also use multiple scripts (or combine them into one) in order to create a more advanced system for your game as shown below in my own project, Blox Sprint:
Here is the full piece of code if you need it:
local Sound = script:WaitForChild("NewJump") -- Your custom sound
local Humanoid = script.Parent:WaitForChild("Humanoid") -- The humanoid of the Character
Humanoid.Jumping:Connect(function(Active) -- The event detecting the jump
if Active == true then -- Checks that it started the jump (not needed for other actions)
script:WaitForChild("NewJump"):Play()
end
end)
local Root = script.Parent:WaitForChild("HumanoidRootPart") -- The part the sounds are stored in
local JumpSound = Root:WaitForChild("Jumping", 5) -- The sound that plays when you jump (change the string depending on what you want to remove)
if JumpSound then
JumpSound:Destroy() -- Remove the sound to stop it from playing
end
Thanks for reading!
Hope you found this useful in some way
Have a good day