Function not consistently firing inbetween events

Hey everyone, I’ve been working on a framework for a game and one of the problems is that a Module doesn’t always return the function being called when it is supposed to.

The framework in question makes it so that the entire game is simulated through modules, that means custom physics, collisions, and animations…There is just one problem - the game doesn’t Consistently fire one of the functions.

My framework has a function called “Simulate” which does the following

  1. Get a deep copy of the most recent game state
  2. Run an initial input step, checking the inputs that have been sent from the players
  3. The next step is to adjust any state machines needed for game play, such as adding a hitbox when an animation reaches a certain frame.
  4. then, apply any physics that have to be added to hitboxes/players

Once you do all of that, the new game state is returned, and can be rendered afterwards.

The problem is that the state machine step doesn’t always launch correctly when the game first starts up. Which means that no hitboxes actually spawn and the animation state never changes.

function module.Simulate(currentState: GameState, p1Input: InputPayload, p2Input: InputPayload): GameState
	
	local returnState: GameState = require(game.ReplicatedStorage.Utility.DeepCopy)(currentState)
	
	--Input state fires just fine
	require(script.Parent.InputStep)(returnState, p1Input, p2Input)
	--State step doesn't always fire when testing the game
	require(script.Parent.StateStep)(returnState)
	--Physics fire just fine.
	require(script.Parent.PhysicsStep)(returnState)
	
	return returnState
end

Is there a reason why this happens? There is no error being returned and the script does not halt when doing this, so clearly there isn’t anything wrong with syntax. And when the state machine DOES load in, it actually works as intended.

EDIT: Here is a video showcasing what is actually happening, the first few times I launch the game it does not work. However the last attempt the state machine works just fine https://youtu.be/mW2sJjRrGyc