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