I want to make the code so it plays the sound only when the event fires, not all the time.
Here’s my script:
spawn(function()
while true do
while track.Animation.AnimationId == Animations.Running.Animation.AnimationId do
local connection
connection = track:GetMarkerReachedSignal("Step"):Connect(function(frame)
connection:Disconnect()
spawn(function()
local sound = steps[math.random(1,#steps)]:Clone()
sound.Parent = script.Parent.View
sound:Play()
wait(sound.TimeLength)
sound:Destroy()
end)
end)
wait()
end
wait(0.1)
end
end)
local debounce = false
spawn(function()
while true do
while track.Animation.AnimationId == Animations.Running.Animation.AnimationId and debounce==false do
debounce=true
local connection
connection = track:GetMarkerReachedSignal("Step"):Connect(function(frame)
connection:Disconnect()
spawn(function()
local sound = steps[math.random(1,#steps)]:Clone()
sound.Parent = script.Parent.View
sound:Play()
wait(sound.TimeLength)
sound:Destroy()
debounce=false
end)
end)
wait()
end
wait(0.1)
end
end)
have you tried to try for example Player.Character.Humanoid.Running:Connect()?
If not, then try to do it, it will react to the movement of the character, that is, for example:
Player.Character.Humanoid.Running:Connect(function(speed)
if speed>0 then
RunLoopAnmation() --will run a loop of your animation
else
StopLoopAnimation() --will stop a loop of your animation
end
end)