How do I Make Arms Move with Camera?

Hi,

All I need is something very simple; How do I Make Arms Move with Camera?.

Someone gave me a script a few days ago but it’s very glitchy.

Local Script in StarterGui:

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local event = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("moveArms")

local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local camera = game.Workspace.CurrentCamera

updateSpeed = 0.4
	
character:WaitForChild("Right Arm")
character:WaitForChild("Left Arm")

game:GetService("RunService").Stepped:Connect(function()
	local camCF = camera.CoordinateFrame
	local distance = (character.Head.Position - camCF.p).magnitude
	if humanoid.Health ~= 0 then
		event:FireServer(rightShoulder, rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed), leftShoulder, leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0), updateSpeed))
	else
		event:FireServer(rightShoulder, CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0), leftShoulder, CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0))
	end
end)

Server Script in ServerScriptService:

game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("moveArms").OnServerEvent:Connect(function(plr, one, oneC, two, twoC)
	one.C0 = oneC
	if two ~= nil then
		two.C0 = twoC
	end
end)

Does anyone have a script, or is willing to help make mine less glitchy?

6 Likes

Here is a video showing what the script does:

As you can see it’s very glitchy.

Well, it would appear that you fire a remote event and change the values on the server.

Not only is this a bad idea due to the fact you are firing it in a renderstepped (which causes lots of requests), there is obviously going to be a delay due to the fact you are using remote events. Just set it on the client in the renderstepped rather than the server.

If other players have to see it, just fire it every 0.5 seconds for others to see. Keep setting the values in a renderstepped though so it looks smooth on the client.

2 Likes

how would i make it fire the remote every 0.5 seconds? do i have to write code outside of renderstepped?

soemthing like this?

while true do
wait(0.5)
-- fire remote
end

can i also fire it faster than 0.5 second because i feel like it would look weird to other players

1 Like

Thats what I would do. Something like this should work:
(I have 0 clue about how motor6ds and their properties work, which is why I’m not sure if this would work.)

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local event = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("moveArms")

local humanoid = character:WaitForChild("Humanoid")
local torso = character:WaitForChild("Torso")
local rightShoulder = torso:WaitForChild("Right Shoulder")
local leftShoulder = torso:WaitForChild("Left Shoulder")
local camera = game.Workspace.CurrentCamera

updateSpeed = 0.4

character:WaitForChild("Right Arm")
character:WaitForChild("Left Arm")

game:GetService("RunService").Stepped:Connect(function()
	local camCF = camera.CoordinateFrame
	local distance = (character.Head.Position - camCF.p).magnitude
	if humanoid.Health > 0 then
		rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed)
		leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
	else
		rightShoulder.C0 = CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0)
		leftShoulder.C0 = CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0)
	end
end)

while true do
	local camCF = camera.CoordinateFrame
	local distance = (character.Head.Position - camCF.p).magnitude
	if humanoid.Health > 0 then
		event:FireServer(rightShoulder, rightShoulder.C0:lerp((camCF * CFrame.new(1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, math.pi/2, 0), updateSpeed), leftShoulder, leftShoulder.C0:lerp((camCF * CFrame.new(-1, -1, 0)):toObjectSpace(torso.CFrame):inverse() * CFrame.Angles(0, -math.pi/2, 0), updateSpeed))
	else
		event:FireServer(rightShoulder, CFrame.new(1, 0.5, 0) * CFrame.Angles(0, math.pi/2, 0), leftShoulder, CFrame.new(-1, 0.5, 0) * CFrame.Angles(0, -math.pi/2, 0))
	end
	
	wait(.5)
end

Its completely up to you. I would recommend a number from 0.1 - 0.5, anything lower would be bad and anything higher would look weird.

8 Likes

Thank you very much! It works perfectly, but sorry it took me a while to reply. I thought it was broken and I was trying to fix it, but I actually just someonehow deleted the server script.

1 Like

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