Running render step with animations

I have one script controlling all npcs in the game which is being ran with heartbeat. My issue is that the npc animation is jittery because the heartbeat causes the animation to start again before it finishes, so I’m wondering how I can have the npc complete the animation while still including it within a render step.

2 Likes

Use debounces, they basically work as followed:

local test do -- make this a global variable
   local db = false -- this is only readable in the do end statement (its a private variable)

   function test()
      if not db then -- make it unable to run when you are already running it
         db = not db -- make it true so it doesnt run again
         wait(2) -- wait time
         db = not db -- make it false so it can run again
      end
   end
end

Instead in your cause you should use AnimationTrack.Stopped:Wait()
instead of the wait(2)

db = not db should be at the start and the end of the function.

Using render step won’t help in this case. You could use the Animation.Stopped event to yield the code until the animation is done playing.

Denounces are not recommended. I would still suggest you to read my reply

Chief, they are called debounces, but other then that I was editting my messages to add the last part to it.

With that being said he could use db tables for each animator like so:

--this should be outside of the function
local animators = {} -- [NpcModel.Humanoid.Animator] = true/false (in a table)

-- use a for loop to gather all animator's of each NPC.

-- this should be in the function:
for animator, debounceBool pairs(animators)
   if not debounceBool then
      animators[animator] = true
      local animationTrack
      -- play animation
      AnimationTrack.Stopped:Connect(function()
         animators[animator] = false 
      end)()
   end
end

This is a much better solution as it works per NPC.

That wasn’t what I was expecting but okay.

https://developer.roblox.com/en-us/api-reference/event/RunService/RenderStepped

RenderStepped should only be used in local scripts when to manipulate the local player’s camera/character only, for other requirements (such as animations) you should be opting to use Heartbeat/Stepped instead.

Do you have a script which you could provide? It’s much easier to offer assistance when a script is shown.