Footsteps script wont work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to achieve walking sounds!

  2. What is the issue? Include screenshots / videos if possible!
    It just refuses to trigger

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Couldnt find any

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

wait(1)
hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
while true do
	
	wait()
	if hum:IsA("Humanoid") then
		footsteps = hum.RootPart:WaitForChild("Running")
		if footsteps:IsA("Sound") then
			footsteps.Volume = 1.5
			if hum.FloorMaterial == "DiamondPlate" then
				footsteps.SoundId = "rbxassetid://" .. 9064974448
				footsteps.PlaybackSpeed = 0.97
			elseif hum.FloorMaterial == "Wood" then
				footsteps.SoundId = "rbxassetid://" .. 5446226292
				footsteps.PlaybackSpeed = 1.23
			elseif hum.FloorMaterial == "Marble" then
				footsteps.SoundId = "rbxassetid://" .. 9083855231
				footsteps.PlaybackSpeed = 1
			else
				footsteps.SoundId = "rbxassetid://" .. 6506537704
				footsteps.PlaybackSpeed = 1.56
			end
		end
	end
end
1 Like

Try adding some print statements throughout the function.

Also, maybe try checking to see if the Humanoid.MoveDirection is more than one to make sure the humanoid is moving. Wrap this in an if statement.

its local, and i mean that it wont change the sfx. i know the floormaterial changes.

Are there any errors or warnings in the output?

no, idk why you would think there were

1 Like

I’m not super familiar with how sounds work, are you sure the sound would be playing if the code doesn’t call :Play on it anywhere?

Do sounds automatically detect changes to their SoundId property and change the sound they’re playing or do they need to have Play called on them again to update that?

Are you sure that footsteps is a sound? If it’s not, the code wouldn’t work with no warning. (It might be better practice to throw a warning when that happens, or wrap the loop in a task.spawn and throw an error.)

(Just a random note, Realism has a really good footsteps sound creator with sounds for all sorts of materials that works really well.)

im coding everything myself/with forum help. everything works, except the sound doesnt change. test the code for yourself. its a localscript in startergui.

1 Like

It might be that a sound won’t change the sound it’s already playing unless Sound:Play() is called again, even if .SoundId is changed.

Maybe in each of your if statements, you could add something like:

if footsteps.SoundId ~= "rbxassetid://" .. 9064974448 then
	footsteps.SoundId = "rbxassetid://" .. 9064974448
	footsteps.PlaybackSpeed = 0.97
	footsteps:Play()
end

or more concisely:

footsteps = hum.RootPart:WaitForChild("Running")
	if footsteps:IsA("Sound") then
		initialSoundId = footsteps.SoundId
		footsteps.Volume = 1.5
		if hum.FloorMaterial == "DiamondPlate" then
			footsteps.SoundId = "rbxassetid://" .. 9064974448
			footsteps.PlaybackSpeed = 0.97
		elseif hum.FloorMaterial == "Wood" then
			footsteps.SoundId = "rbxassetid://" .. 5446226292
			footsteps.PlaybackSpeed = 1.23
		elseif hum.FloorMaterial == "Marble" then
			footsteps.SoundId = "rbxassetid://" .. 9083855231
			footsteps.PlaybackSpeed = 1
		else
			footsteps.SoundId = "rbxassetid://" .. 6506537704
			footsteps.PlaybackSpeed = 1.56
		end
		-- Play the sound again if the sound changed
		if footsteps.SoundId ~= initialSoundId then
			footsteps:Play()
		end
	end
end

That way, when your code changes the sound, it also plays the sound again to hopefully update the sounds that’s playing.


You also might want to consider preloading the sound assets, so there isn’t a pause when the character first walks on a new material for the new sound to load.

You can do that with ContentProvider:PreloadAsync(…)

We can’t test it because you never send the full code. What is hum.RootPart:WaitForChild("Running")? A bool value?

Please use task.wait instead.

I mean that’s fine, but your approach to footstep is just screaming hard coding.

if hum:IsA("Humanoid") then
		footsteps = hum.RootPart:WaitForChild("Running")
		if footsteps:IsA("Sound") then
			footsteps.Volume = 1.5
			if hum.FloorMaterial == "DiamondPlate" then
				footsteps.SoundId = "rbxassetid://" .. 9064974448
				footsteps.PlaybackSpeed = 0.97
			elseif hum.FloorMaterial == "Wood" then
				footsteps.SoundId = "rbxassetid://" .. 5446226292
				footsteps.PlaybackSpeed = 1.23
			elseif hum.FloorMaterial == "Marble" then
				footsteps.SoundId = "rbxassetid://" .. 9083855231
				footsteps.PlaybackSpeed = 1
			else
				footsteps.SoundId = "rbxassetid://" .. 6506537704
				footsteps.PlaybackSpeed = 1.56
			end
		end

The amount of if statements… DAMN. I recommend you check out uglyburger0’s footstep module as I personally use it in my own game and it’s wayyyyyy easier to implement.

I wasn’t sure if there were because you didn’t say if you did or not. I wasn’t sure as maybe you forgot. I also didn’t know if the animations weren’t loading properly.

bruh it IS the full code. CANT ANYONE UNDERSTAND HOW I CODE?!

nevermind, i fixed it.

wait(1)
hum = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
if hum:IsA("Humanoid") then
	footsteps = hum.RootPart:WaitForChild("Running")
	if footsteps:IsA("Sound") then
		footsteps.Volume = 1.5
		while true do

			wait()
			
			if hum.FloorMaterial == Enum.Material.DiamondPlate then
				footsteps.SoundId = "rbxassetid://" .. 9064974448
				footsteps.PlaybackSpeed = 0.97
			elseif hum.FloorMaterial == Enum.Material.Wood then
				footsteps.SoundId = "rbxassetid://" .. 5446226292
				footsteps.PlaybackSpeed = 1.23
			elseif hum.FloorMaterial == Enum.Material.Marble then
				footsteps.SoundId = "rbxassetid://" .. 9083855231
				footsteps.PlaybackSpeed = 1
			else
				footsteps.SoundId = "rbxassetid://" .. 6506537704
				footsteps.PlaybackSpeed = 1.56
			end
		end
	end
end

don’t need to get all worked up lol

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.