State replication issues

Hi, I currently have a player state machine (Handles the player states: Attacking, walking, etc…). But there’s a prevalent issue regarding with replication: when the server and the client update a state simultaneously (or close), the outcome is extremely unpredictable due to the replication delay. For example:

    -- Player fired the gun while aiming, the player will now be put in Aiming state

	task.wait(args.gadgetStats.waitBtwAtk)

	if plr.Character.info.State.Value == "Firing" then
		plr.Character.info.State.Value = "Aiming"
	end

However, player can remove their aiming at any given time, which will make the state unpredictable:


That graph pretty much resembles my current issue

Thanks in advance!

1 Like

Hello Shadow_TheDev!

Instead of allowing the server to control the client states, why not just have them verify that state is possible?

In my weapons system, the client controls the state (aiming, firing, etc) and the server has no knowledge of their state. If you could reply with why state replication is important, it would be more helpful to understand.

While its nice to verify that a client is aiming to perform an attack or fire a weapon, it is only essential in my opinion to verify they have enough ammo, the position and target of the attack is possible, and handle the case like that.

If you could, just reply with why you have it necessarily required for the server to have the clients state and replicate it as such.

1 Like

Hey there!

The reason I chose to replicate the states to the server is that there are multiple effects that are based off of the player’s state (Eg: x2 Damage when the player is Stunned, etc…), so I want the states on the server to be as accurate as possible

Furthermore, the states also act as a debounce for the actions. While in my case, changing states on the server isn’t necessary but I can foresee other situations that it will be required.

Thanks.

Edit: I still need help in this one, using intrinsic locks would technically work but remotes would still be utilized so the delay would be too sizable

1 Like