Trying to figure out how to make my footstep sounds delay be affected by WalkSpeed

So I have some code here that will play a footstep sound that is perfectly synced with my animation currently while my WalkSpeed is 10 the delay or wait I use is wait(0.45) how can I change this number based on the speed of the player so for example a greater delay for a slower WalkSpeed?
heres my code;

local function Movement_Update(deltaTime)
	if MOVEMENT_FUNCTIONS:CheckMovement()--[[checks if player is moving]] then
		if not stepDebounce then
			stepDebounce = true;
			
			sound.SoundId = footsteps_functions:get_Material();
			sound.Parent = nil;
			sound.Parent = humanoidRootPart;
			
			wait(0.45)
			
			stepDebounce = false;
		end;
	end;
end

If you have a custom animation, theres an event roblox has called :GetMarkerReachedSignal() which allows you to create an event function whenever its called (of course it scales with your animation speed too) which makes it such a great tool for stuffs like this.

https://developer.roblox.com/en-us/api-reference/function/AnimationTrack/GetMarkerReachedSignal

However if it’s not a custom animation and it’s a roblox one you’d have to figure out how often the animation should play at 16 walkspeed and base it off of that with an algorithm like speed/theoreticalnum to get a number based off of the walkspeeds.

1 Like

Most accurate way in doing it is to just raycast from the foot down and if the ray detects anything then you can assume that the feet touched the ground, If you don’t want to use raycast I could create a formula based on walkspeed if you want (assuming your using rbx walking animations)

This seems very cool and I never knew about this. However how can I refrence the running animation inside roblox default script? because It seems as if I have to use the actual value they used to load the animation.
I cant just say

character.Animate.run.RunAnim:GetMarkerReachedSignal("Step"):Connect(function(paramString)
	print(paramString)
end)

I have to say

local walkAnimTrack = humanoid.Animator:LoadAnimation(character.Animate.run.RunAnim)

walkAnimTrack:GetMarkerReachedSignal("Step"):Connect(function(paramString)
	print(paramString)
end)

So as you said, you need to have the animation loaded and played to have the function run. What do you mean by default script btw, I’m a lil’ confused on that.

Well see the way animations are played for the defualt character are through a roblox script generated on game test heres what it looks like
image
now this script is used for handling playing and loading animations I just set the runAnim animationId to my custom animation so I dont know how I could detect the load animation unless I detect and play footstep sounds in this script which I dont really want to do.

Honestly I’d rather do it formula based it’d be unorganized and too much work to make it to use functions however the default roblox animation script has a formula made in it so I can probably use that to make it.

Use the WalkSpeed property of the Humanoid instance in whatever calculation is used to determine how frequently the sound should play etc.

This is my preferred method. It’s especially important for skinned meshes that do not generate physics with their animations.