Replicating walk sounds

I have a footstep sound system, however you can easily exploit it to spam the sounds.
The way I have it right now is:
The Animate localScript has an added if statement in the keyFrameReachedFunc function:

function keyFrameReachedFunc(frameName)
	if (frameName == "End") then

		local repeatAnim = currentAnim
		-- return to idle if finishing an emote
		if (emoteNames[repeatAnim] ~= nil and emoteNames[repeatAnim] == false) then
			repeatAnim = "idle"
		end
		
		local animSpeed = currentAnimSpeed
		playAnimation(repeatAnim, 0.0, Humanoid)
		setAnimationSpeed(animSpeed)
	end
	
    -- this here
	if(frameName == "WalkSound") then
		script.Parent.Scripts.Walk:FireServer()
	end
end

Then, the server handles the event and plays the sounds. (there is a security feature that checks if the player firing the remote is that character)

The obvious issue here is that you can spam your own footstep sounds.
How can I prevent that while still replicating to other players?

I tried editing the RbxCharacterSounds script, but to no avail since there isnt an easy way to detect keyFrameReached on a already playing animation

Also, I use keyFrameReached so the sounds completely line up, my issue with a while loop system was that console and mobile players’ sounds didnt line up with character speed (if you move the joystick halfway out, not fully) or if you walk into a wall at an angle, slowing you down

Any help?

1 Like

Just wrote this into RbxCharacterSounds, in the initializeSoundSystem function:

    local function keyFrameReached(frameName)
		if frameName == "WalkSound" then
			print("lol")
		end
	end
	
	humanoid.Animator.AnimationPlayed:Connect(function(anim)		
		anim.KeyframeReached:Connect(keyFrameReached)
	end)

This works, but is there any possible memory leaks here?

1 Like

Chat I think we need to revive this post. I’m also trying to implement footstep sounds that replicate to other clients as well, but I don’t know if it’s well-optimized enough.