Two remote events are out of sync, causing split second weirdness

I have two remote events, one controls the head rotation, and the other controls the movement of the body, they are separate as the head constantly updates rotation, while the body only moves on a button press. The problem with this is that when lying down, the body moves parallel to the ground, and the head with it, then a split second later, the head moves up to its correct position. This is most likely due to the split between the remote events.

I have tried to add a simple head mover to the remote event that moves the body, but unfortunately, that does not work. I then tried to add a separate neck head mover to the body mover, similar to how it moves the body, which worked. Still, unfortunately, unequipping and re-equipping, the gun rotated the head awkwardly so that it was looking backward and down. So I removed that.

Here is the body mover:

game.ReplicatedStorage.Stancer.OnClientEvent:Connect(function(Player,Name,Humanoid,Root,StanceChangeSpeed,NewStance,Neck,TCFM)
	if TruePlayer ~= Player then
		local PreviousOffset = Humanoid.CameraOffset
		local PreviousRootP = Root.C0.p
		Stance = NewStance
		for X = 0, 90, 1.5 / StanceChangeSpeed do
			local Alpha = Sine(X)
			Humanoid.CameraOffset = PreviousOffset:lerp(StanceOffset[Stance+1], Alpha)
			if Name == "Stand" then
				if Stance ~= 0 then break end
				Root.C0 = CF(PreviousRootP:lerp(VEC3(), Alpha)) * CFANG(RAD(-90), 0, RAD(180))
			elseif Name == "Crouch" then
				if Stance ~= 1 then break end
				Root.C0 = CF(PreviousRootP:lerp(VEC3(0, -1, 0), Alpha)) * CFANG(RAD(-90), 0, RAD(180))
			elseif Name == "Prone" then
				if Stance ~= 2 then break end
				Root.C0 = CF(PreviousRootP:lerp(VEC3(0, -2.5, 1), Alpha)) * CFANG(RAD(180), 0, RAD(180))
			end
			RS:wait()
		end
	end
end)

Here is the Head Mover:

game.ReplicatedStorage.Neckrotator.OnClientEvent:Connect(function(Player,Neck,TCFM,HeadRot)
	if TruePlayer ~= Player then
		Neck.C1 = CFANG(HeadRot,0,0)
		Neck.C0 = TCFM
	end
end)

For Completion, Here are the firing sides of the remote events:

INSERT(Connections, RS:connect(function()
	local MDir = M2.UnitRay.Direction.unit

	local HRPCF = HRP.CFrame * CF(0, 1.5, 0) * CF(Humanoid.CameraOffset)
	TCFM = Torso.CFrame:toObjectSpace(HRPCF)
	Neck.C0 = TCFM

	if MDir.y == MDir.y then
		HeadRot = -math.asin(MDir.y)
		Neck.C1 = CFANG(HeadRot,0,0)
		game.ReplicatedStorage.Neckrotator:FireServer(Neck,TCFM,HeadRot)
function Stand(OnDeselected)
	local LHip = Torso["Left Hip"]
	local RHip = Torso["Right Hip"]
	local Root = HRP.RootJoint
	Stance = 0
	if S.StanceAnimation and (not OnDeselected) then
		spawn(function()
			local PreviousOffset = Humanoid.CameraOffset
			local PreviousRootP = Root.C0.p
			for X = 0, 90, 1.5 / S.StanceChangeSpeed do
				if Stance ~= 0 then break end
				local Alpha = Sine(X)
				Humanoid.CameraOffset = PreviousOffset:lerp(StanceOffset[1], Alpha)
				Root.C0 = CF(PreviousRootP:lerp(VEC3(), Alpha)) * CFANG(RAD(-90), 0, RAD(180))
				RS:wait()
			end
		end)
		game.ReplicatedStorage.Stancer:FireServer("Stand",Humanoid,Root,S.StanceChangeSpeed,Stance,Neck,TCFM)
		TweenJoint(ABWeld, CF(), CF(), Sine, S.StanceChangeSpeed)
		TweenJoint(LHip, CF(-1, -1, 0) * CFANG(0, RAD(-90), 0), CF(-0.5, 1, 0) * CFANG(0, RAD(-90), 0), Sine, S.StanceChangeSpeed)
		TweenJoint(RHip, CF(1, -1, 0) * CFANG(RAD(-180), RAD(90), 0), CF(0.5, 1, 0) * CFANG(RAD(-180), RAD(90), 0), Sine, S.StanceChangeSpeed)
	elseif OnDeselected then
		game.ReplicatedStorage.StanceReseter:FireServer(Humanoid,Root,LHip,RHip)
		Humanoid.CameraOffset = StanceOffset[1]
		ABWeld.C0 = CF()
		ABWeld.C1 = CF()
		LHip.C0 = CF(-1, -1, 0) * CFANG(0, RAD(-90), 0)
		LHip.C1 = CF(-0.5, 1, 0) * CFANG(0, RAD(-90), 0)
		RHip.C0 = CF(1, -1, 0) * CFANG(RAD(-180), RAD(90), 0)
		RHip.C1 = CF(0.5, 1, 0) * CFANG(RAD(-180), RAD(90), 0)
		Root.C0 = CFANG(RAD(-90), 0, RAD(180))
	end
end
1 Like

It looks like the only solution would be adding something to the Body mover.

1 Like

May I ask why you aren’t using animations?

I have no clue, I am fixing a old script for 2014-2016 and It does not use animations, as such, neither am I. I am converging on a fix for the issue though, It works perfectly except when deselecting while the stance is changing does not move the legs back to the correct spot, but I am also fixing that as I need to get my animator function to stop when I deselect.

1 Like

I have experimented with animations, But Unfortunately they wont work in the current state of the script as the fake arms that it makes use Welds, and not Motor 6Ds. Maybe it would be Possible to replace the Welds with the motors but I have not tried that.

1 Like

I am pretty sure I have fixed all issues like this and with some tweaks to the rest of the script it works pretty well:

game.ReplicatedStorage.Stancer.OnClientEvent:Connect(function(Player,Name,Humanoid,Root,StanceChangeSpeed,NewStance,Neck,TCFM)
	if TruePlayer ~= Player then
		local PreviousOffset = Humanoid.CameraOffset
		local PreviousRootP = Root.C0.p
		local PreviousNeckP = Neck.C0.p
		local PreviousStance = Stance
		Stance = NewStance
		for X = 0, 90, 1.5 / StanceChangeSpeed do
			local Alpha = Sine(X)
			if (not Selected) then break end
			Humanoid.CameraOffset = PreviousOffset:lerp(StanceOffset[Stance+1], Alpha)
			if Name == "Stand" then
				if Stance ~= 0 then break end
				Root.C0 = CF(PreviousRootP:lerp(VEC3(), Alpha)) * CFANG(RAD(-90), 0, RAD(180))
				Neck.C0 = CF(PreviousNeckP:lerp(VEC3(0,1.5,0), Alpha))
			elseif Name == "Crouch" then
				if Stance ~= 1 then break end
				Root.C0 = CF(PreviousRootP:lerp(VEC3(0, -1, 0), Alpha)) * CFANG(RAD(-90), 0, RAD(180))
				if PreviousStance == 2 then
					Neck.C0 = CF((PreviousNeckP*VEC3(1,1,-1)):lerp(VEC3(0,1.5,0), Alpha))
				else
					Neck.C0 = CF((PreviousNeckP):lerp(VEC3(0,1.5,0), Alpha))
				end
			elseif Name == "Prone" then
				if Stance ~= 2 then break end
				Root.C0 = CF(PreviousRootP:lerp(VEC3(0, -2.5, 1), Alpha)) * CFANG(RAD(180), 0, RAD(180))
				Neck.C0 = CF((PreviousNeckP*VEC3(0,0,0)):lerp(VEC3(0, 1, 1), Alpha)) * CFANG(RAD(90), 0, 0)
			end
			RS:wait()
		end
	end
end)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.