Hello, I am working on a first person shooter and am trying to make the players arms move up and down with the camera. I’ve made a script which does that, but it makes the arms move horizontally too. I’ve seen games like Survive and Kill the Killers in Area 51 !!! do what I am trying to do. How would I make the arms move only vertically?
This is my script
local player = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
local humanoid = script.Parent:WaitForChild('Humanoid')
local humanoidRootPart = script.Parent:WaitForChild('HumanoidRootPart')
local rightShoulder = script.Parent.Torso:WaitForChild('Right Shoulder')
local leftShoulder = script.Paren.Torso:WaitForChild('Left Shoulder')
local runService = game:GetService('RunService')
runService.RenderStepped:Connect(function()
local cameraCFrame = camera.CFrame
rightShoulder.C0 = (cameraCFrame * CFrame.new(1, -1, -0.8)):ToObjectSpace(humanoidRootPart.CFrame):Inverse() * CFrame.Angles(0, math.pi / 2, 0)
leftShoulder.C0 = (cameraCFrame * CFrame.new(-1, -1, -0.8)):ToObjectSpace(humanoidRootPart.CFrame):Inverse() * CFrame.Angles(0, -math.pi / 2, 0)
end)
--CLIENT
do
local Game = game
local Workspace = workspace
local RunService = Game:GetService("RunService")
local ReplicatedStorage = Game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:FindFirstChild("RemoteEvent") or ReplicatedStorage:WaitForChild("RemoteEvent")
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:FindFirstChildOfClass("Humanoid") or Character:WaitForChild("Humanoid")
local RigType = Humanoid.RigType.Name
local LeftShoulder, RightShoulder
if RigType == "R6" then
local Torso = Character:FindFirstChild("Torso") or Character:WaitForChild("Torso")
LeftShoulder = Torso:FindFirstChild("Left Shoulder") or Torso:WaitForChild("Left Shoulder")
RightShoulder = Torso:FindFirstChild("Right Shoulder") or Torso:WaitForChild("Right Shoulder")
elseif RigType == "R15" then
local LeftUpperArm = Character:FindFirstChild("LeftUpperArm") or Character:WaitForChild("LeftUpperArm")
local RightUpperArm = Character:FindFirstChild("RightUpperArm") or Character:WaitForChild("RightUpperArm")
LeftShoulder = LeftUpperArm:FindFirstChild("LeftShoulder") or LeftUpperArm:WaitForChild("LeftShoulder")
RightShoulder = RightUpperArm:FindFirstChild("RightShoulder") or RightUpperArm:WaitForChild("RightShoulder")
end
if not (LeftShoulder and RightShoulder) then return end
local Camera = Workspace.CurrentCamera
local function OnRenderStep()
local LeftC0 = LeftShoulder.C0
local RightC0 = RightShoulder.C0
local LookVector = Camera.CFrame.LookVector
LeftC0 = if RigType == "R6" then CFrame.lookAt(LeftC0.Position, LeftC0.Position + Vector3.new(LeftC0.LookVector.X, LookVector.Y, LookVector.Z)) elseif RigType == "R15" then CFrame.lookAt(LeftC0.Position, LeftC0.Position + Vector3.new(LeftC0.LookVector.X, LookVector.Y, LeftC0.LookVector.Z)) else CFrame.new(0, 0, 0)
RightC0 = if RigType == "R6" then CFrame.lookAt(RightC0.Position, RightC0.Position + Vector3.new(RightC0.LookVector.X, LookVector.Y, LookVector.Z)) elseif RigType == "R15" then CFrame.lookAt(RightC0.Position, RightC0.Position + Vector3.new(RightC0.LookVector.X, LookVector.Y, RightC0.LookVector.Z)) else CFrame.new(0, 0, 0)
LeftShoulder.C0 = LeftC0
RightShoulder.C0 = RightC0
RemoteEvent:FireServer(LeftShoulder, RightShoulder, LeftC0, RightC0)
end
RunService.RenderStepped:Connect(OnRenderStep)
end
--SERVER
local Game = game
local ReplicatedStorage = Game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.RemoteEvent
local function OnRemoteFired(Player, LeftShoulder, RightShoulder, LeftC0, RightC0)
LeftShoulder.C0 = LeftC0
RightShoulder.C0 = RightC0
end
RemoteEvent.OnServerEvent:Connect(OnRemoteFired)