I AM NOT USING STOLEN ASSETS RVVZ, PLEASE DONT SUE ME THANKS LOVE U
In case you have no idea what I’m talking about, Criminality uses a cool system where the footstep sounds alternate between steps on different materials, and this is actually relatively simple so I thought I would make a tutorial for anyone who ends up wanting to make something like this.
Variables (boring zzzzzzzzz)
This is just defining the variables, nothing special.
local Player = game.Players.LocalPlayer
local Character = Player.Character -- Player's Character
local DefaultSound = Character.HumanoidRootPart:WaitForChild("Running").SoundId -- This is the sound effect for running, which we want to replace.
Ok, so now we can get into actual coding. First, we need to make a table with different sound id’s for different materials. Here is an example of what this would look like;
local MaterialTable = {
[Enum.Material.Grass] = {
"rbxassetid://id",
"rbxassetid://id2"
},
[Enum.Material.Fabric] = {
"rbxassetid://id",
"rbxassetid://id2"
},
[Enum.Material.Glass] = {
"rbxassetid://id",
"rbxassetid://id2"
},
[Enum.Material.Metal] = {
"rbxassetid://id",
"rbxassetid://id2"
},
[Enum.Material.Sand] = {
"rbxassetid://id",
"rbxassetid://id2"
},
[Enum.Material.Wood] = {
"rbxassetid://id",
"rbxassetid://id2"
}
}
As you can see, you need 2 sounds for each material, I reccomend just using a regular and slightly pitched down version. This is because it sounds better having a different sound for each “step”.
Next, we need to play each of these sounds when the character is walking. Luckily, we don’t have to do any detection for this as roblox has a built in sound effect which we can change (which we defined in the variables section), and we can also detect when the material you are walking on changes using a barely known property of the players humanoid, “FloorMaterial”. This is like the holy grail for this system, and completely changes the game.
Detect when material changes
Character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
Uhh floormaterial
local FloorMaterial = Character.Humanoid.FloorMaterial
Generate a random number between 1 and 2 which will determing which step sound is played (you can also switch this for a system which plays them in order (alternate between 1 and 2 using += and -=))
local rand = math.random(1, 2)
Check if the material is in our material table, then change the soundid of the walking to our sound id
if MaterialTable[FloorMaterial] then
Character.HumanoidRootPart:WaitForChild("Running").SoundId = MaterialTable[FloorMaterial][rand]
Otherwise, if the sound is already playing, wait till it ends then switch it back to the default sound so we can change it again later
else
if Character.HumanoidRootPart:WaitForChild("Running").IsPlaying then
Character.HumanoidRootPart:WaitForChild("Running").Ended:Connect(function()
Character.HumanoidRootPart:WaitForChild("Running").SoundId = DefaultSound
Finally, if we put it all together it will look something like this!
local Player = game.Players.LocalPlayer
local Character = Player.Character
local DefaultSound = Character.HumanoidRootPart:WaitForChild("Running").SoundId
local MaterialTable = {
[Enum.Material.Grass] = {
"rbxassetid://id",
"rbxassetid://id"
},
[Enum.Material.Fabric] = {
"rbxassetid://id",
"rbxassetid://id"
},
[Enum.Material.Glass] = {
"rbxassetid://id",
"rbxassetid://id"
},
[Enum.Material.Metal] = {
"rbxassetid://id",
"rbxassetid://id"
},
[Enum.Material.Sand] = {
"rbxassetid://id",
"rbxassetid://id"
},
[Enum.Material.Wood] = {
"rbxassetid://id",
"rbxassetid://id"
}
}
Character.Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
local FloorMaterial = Character.Humanoid.FloorMaterial
local rand = math.random(1, 2)
if MaterialTable[FloorMaterial] then
Character.HumanoidRootPart:WaitForChild("Running").SoundId = MaterialTable[FloorMaterial][rand]
else
if Character.HumanoidRootPart:WaitForChild("Running").IsPlaying then
Character.HumanoidRootPart:WaitForChild("Running").Ended:Connect(function()
Character.HumanoidRootPart:WaitForChild("Running").SoundId = DefaultSound
end)
end
end
end)
Obviously this is a pretty basic system and it does only change the walking noises on the client, but it can be easily modified to use remote events and play the sounds on the server if you like have hundreds of remote event activations per second for some sick reason!