Can't find a good function for my script

So I wrote a script for footsteps sounds and I can’t find a good function for it
any suggestions for a function I should use?
script:
image

2 Likes

Bigger script:

Possibly walking on different materials plays different sounds?

You can use :GetTouchingParts() to see what material the part is that the player is walking on.

That or just a fancy walking sound effect.

You can just do a loop to constantly check the humanoid state of the player, and if they are, then play the sound.

I Want to make it so in general whenever you’d walk you will hear the sound

In that case, put the if statement inside a loop and but an else statement with sound:Stop() in it.

A more efficient way might be h.Running (an event).

1 Like

The thing is there’s no code that stops the animation after you stop walking ( if it’s looped of course or if it’s not visible in the script ) and if it’s not looped, it will only play once everytime the running state happens because it’s assigned once, you should make that animation variable everytime the humanoid state is running instead of assigning it once, you should use humanoid floor material to detect which material it’s on, if it’s on air, make no sounds play so it won’t bug like your jesus on a invisible plank.

Hope i helped.

This should help you out.

So after all of this I tried making a for i,v loop but it didn’t work:

What you’re doing with your h:getstate == x and not y is this:

if true and not true then -- This will never run

Lua is truthy, so Enum.HumanoidStateType.None will be “true”.

A better way to handle this would be something like this:

if not game.Players.LocalPlayer.Character then
	game.Players.LocalPlayer.CharacterAdded:Wait()
end
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Sound = script.Sound
Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
	if Humanoid.MoveDirection.Magnitude > 0 and not Sound.Playing then
		Sound:Play()
		Sound.PlaybackSpeed = Humanoid.MoveDirection.Magnitude -- optional
	elseif Humanoid.MoveDirection.Magnitude <= 0 then
		Sound:Stop()
	end
end)

Also, your for i,v loop only runs at the start of the game for a small fraction of a second, so the sound will never play.

1 Like

Thank you! although the character you wrote wrong but I found a way to fix it.