-
What do you want to achieve? Make a viewmodel script on first person and i wan’t to make that the players can see the other players arm movement without any issues. Just to make it short i wanted to make a viewmodel script and server side arm movement like in criminality
-
What is the issue? So i was combining the flaming dev’s viewmodel script with server side arm movement script and it turned out like this:
-
What solutions have you tried so far? I tried to find the solution for this on dev forum but i didn’t find any.
I really don’t know how to fix that. If someone can help thank you.
Anyway here’s the scripts:
Flaming dev’s viewmodel script:
local runMult = 10
local walkMult = 4
local swaySpeed = .1 -- 0 is fast 1 is slow
local returnSpeed = .1-- 0 is fast 1 is slow
local smoothingMult = .5-- 0 is fast 1 is slow
-----------------
local OFFSET = 0 -- the forward offset
local X = 0 -- the forward offset
local Y = 0 -- the forward offset
local runService = game:GetService("RunService")
local character = script.Parent
wait(2)
local VM = game.ReplicatedStorage.ViewModelStorage.VM:Clone()
VM.Parent = workspace.CurrentCamera
local leftShoulder = character.Torso["Left Shoulder"]
local rightShoulder = character.Torso["Right Shoulder"]
local sine = 0
function getCFrame(cframe)
local sx, sy, sz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cframe:GetComponents()
local X = math.atan2(-m12, m22)
local Y = math.asin(m02)
local Z = math.atan2(-m01, m00)
return X,Y,Z
end
runService.RenderStepped:Connect(function(deltatime)
character:FindFirstChild("Right Arm").LocalTransparencyModifier = 0
OFFSET = script.OFFSET.Value
X = script.X.Value
Y = script.Y.Value
character:FindFirstChild("Left Arm").LocalTransparencyModifier = 0
local pcframe = workspace.CurrentCamera.CFrame + workspace.CurrentCamera.CFrame.LookVector * OFFSET + workspace.CurrentCamera.CFrame.RightVector * X + workspace.CurrentCamera.CFrame.UpVector * Y
local lerpedRot = VM.PrimaryPart.CFrame:lerp(pcframe,smoothingMult)
local _,_,_,m11,m12,m13,m21,m22,m23,m31,m32,m33 = lerpedRot:components();
local ogPos = pcframe.p;
local newCf = CFrame.new(ogPos.x,ogPos.y,ogPos.z,m11,m12,m13,m21,m22,m23,m31,m32,m33)
VM.PrimaryPart.CFrame = newCf;
local dist = (workspace.CurrentCamera.CFrame.Position - character.Head.Position).Magnitude
if dist < 1 then
rightShoulder.Part0 = VM.Torso
leftShoulder.Part0 = VM.Torso
else
rightShoulder.Part0 = character.Torso
leftShoulder.Part0 = character.Torso
end
end)
local val = 0
local moving = false
while true do
sine = math.sin(val)
wait(.00005)
if character.Humanoid.MoveDirection ~= Vector3.new(0,0,0) then
val += .4
game.TweenService:Create(script.X, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = sine/walkMult}):Play()
if sine < 0 then
game.TweenService:Create(script.Y, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = -sine/walkMult}):Play()
else
game.TweenService:Create(script.Y, TweenInfo.new(swaySpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = sine/walkMult}):Play()
end
else
game.TweenService:Create(script.Y, TweenInfo.new(returnSpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = 0}):Play()
game.TweenService:Create(script.X, TweenInfo.new(returnSpeed,Enum.EasingStyle.Linear,Enum.EasingDirection.Out), {Value = 0}):Play()
end
end
Local Arm movement
local plr = game.Players.LocalPlayer
repeat wait(.1) until plr.Character
local character = plr.Character
local torso = character:WaitForChild("Torso")
local rightarm = character:WaitForChild("Right Arm")
local leftarm = character:WaitForChild("Left Arm")
local leftshoulder = torso:WaitForChild("Left Shoulder")
local rightshoulder = torso:WaitForChild("Right Shoulder")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpgradePosEvent = ReplicatedStorage:WaitForChild("Look") ---your remote event
local camera = game:GetService("Workspace").CurrentCamera
local Mouse = plr:GetMouse()
game:GetService("RunService").RenderStepped:Connect(function()
if leftshoulder and leftarm then
leftshoulder.C0 = CFrame.new(-1, 0.5, -0.2) * CFrame.Angles(math.rad(50) + math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), math.rad(-90), math.rad(52))
end
if rightshoulder and rightarm then
rightshoulder.C0 = CFrame.new(1, 0.5, -0.2) * CFrame.Angles(math.rad(100) + math.asin((Mouse.Hit.p - Mouse.Origin.p).unit.y), math.rad(90), math.rad(-104))
end
end)
while true do
if rightshoulder and rightarm then
UpgradePosEvent:FireServer(rightshoulder,rightshoulder.C0)
end
if leftshoulder and leftarm then
UpgradePosEvent:FireServer(leftshoulder,leftshoulder.C0)
end
wait(.35)
end
Server Arm Movement:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpgradePosEvent = ReplicatedStorage:WaitForChild("Look")
UpgradePosEvent.OnServerEvent:Connect(function(plr, thing, thingC0)
if plr and plr.Character and thing and thing.Parent and thing.Parent.Parent == plr.Character and thingC0 and thing:IsA("Motor6D") then
UpgradePosEvent:FireAllClients(thing, thingC0, plr)
end
end)