Hello!
I am currently working on a script to produce footstep sounds whenever the player’s foot hits the ground, I have tried this using both KeyframeReached and GetMarkerReachedSignal, however this did not produce the desired result.
I am currently using the default roblox walking animation defined in the script, I am not using one made by me, I simply use the default walk with some keyframe events attached.
The issue is, however: I have to manually call :Play() for the events to be registered, and even then it is an infinite loop. This does not make sense to me, since the animation automatically plays when you move around at a certain (low) walkspeed.
I checked the devforum and youtube for resources, but so far there’s no luck.
I will paste my script here for reference, along with some screenshots to further clarify the issue.
Script (LocalScript inserted into the StarterCharacterScripts folder):
local cas = game:GetService("ContextActionService")
local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local atEaseAnimation = script:WaitForChild("AtEase")
--replace standard walking animation with the version where the keyframes are defined in order to listen for the markers being reached
local walkAnim = script.Parent.Animate.walk.WalkAnim
walkAnim.AnimationId = "rbxassetid://7669855144"
local atEaseAnimationTrack = animator:LoadAnimation(atEaseAnimation)
local walkAnimationTrack = animator:LoadAnimation(walkAnim)
local playAnim = "playAnimation"
local function toggleAnimation(actionName, userInputState)
--Check if the AtEase animation is not already playing. If it is: then stop playing it, if not: play it and adjust walkspeeds accordingly for each scenario.
if actionName == playAnim and userInputState == Enum.UserInputState.Begin then
if atEaseAnimationTrack.IsPlaying then
character.HumanoidRootPart.Running.PlaybackSpeed = 1.85
atEaseAnimationTrack:Stop()
humanoid.WalkSpeed = 16
else
character.HumanoidRootPart.Running.PlaybackSpeed = 1.6
atEaseAnimationTrack:Play()
humanoid.WalkSpeed = 8
end
end
end
--waiting for the event markers to be reached as defined in the animator
walkAnimationTrack:GetMarkerReachedSignal("Footstep"):Connect(function(paramString)
print(paramString)
end)
--bind the AtEase animation to play or stop, depending on the situation, whenever the R key is pressed.
cas:BindAction(playAnim, toggleAnimation, false, Enum.KeyCode.R)
My animation, as you can see there are markers clearly present.
Extra screenshot to show the spelling is correct
The default walking animation got replaced with the animation where markers are defined
However, as you can see in the clip below: nothing ends up printing. I have to call :Play() for an animation that should be automatically playing which is a bit absurd to me.
https://gyazo.com/d48625e137283f521587ba145cd8c95c
EDIT: added extra screenshot to clarify the spelling of the keyframe events.