Hey there! I have a problem related to a first person viewmodel script I’m working on that has stumped all my fellow colleagues on this issue, and I hope you can help fix this problem along me.
My issue is that on a first person viewmodel weapons system i’m working on (that is based off of pretty much the best first person viewmodel tutorial by EgoMoose ) is that for some reason, the arm rig and the weapon are in the Camera, but the arms don’t follow the camera but the weapon does.
I’ve checked to make sure the arms were unanchored and the head to be anchored, yet the problem still persisted. However, to my revelation it seems that if i anchored the weapon entirely, it’d do the same thing as the arms did.
Keep in mind there are aboslutely no errors in the Output that i had, and if you want to check my code, here it is.
local camera = game.Workspace.CurrentCamera
local humanoid = game.Players.LocalPlayer.CharacterAdded:Wait():WaitForChild("Humanoid")
local viewModel = game.ReplicatedStorage:WaitForChild("viewmodel"):Clone()
local repWeapon = game.ReplicatedStorage:WaitForChild("AR15Model")
local weapon = repWeapon:Clone()
local Handle = weapon.Handle
local Mag = weapon.Mag
local UserInputService = game:GetService("UserInputService")
local Player = game:GetService("Players").LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
weapon.Parent = viewModel
viewModel.Parent = camera
local aimCount = 0
local offset = weapon.Handle.CFrame:inverse() * weapon.Aim.CFrame
local joint = Instance.new("Motor6D")
joint.C0 = CFrame.new(0.5, -1, -3) -- what I found fit best imo
joint.Part0 = viewModel.Head
joint.Part1 = weapon.Handle
joint.Parent = viewModel.Head
local function onDied()
viewModel.Parent = nil
end
local function updateArm(key)
local shoulder = viewModel[key.."UpperArm"][key.."Shoulder"]
-- calculate worldspace arm cframe from Right or Left part in the weapon model
local cf = weapon[key].CFrame * CFrame.Angles(math.pi/2, 0, 0) * CFrame.new(0, 1.5, 0)
-- update the C1 value needed to for the arm to be at cf (do this by rearranging the joint equality from before)
shoulder.C1 = cf:inverse() * shoulder.Part0.CFrame * shoulder.C0
end
local function onUpdate(dt)
viewModel.Head.CFrame = camera.CFrame
updateArm("Right")
updateArm("Left")
end
game:GetService("UserInputService").InputBegan:Connect(onInputBegan)
game:GetService("UserInputService").InputEnded:Connect(onInputEnded)
humanoid.Died:Connect(onDied)
game:GetService("RunService").RenderStepped:Connect(onUpdate)
This is all I really have for the code, it’s in a Tool with a server script and a client side script, if you want more info about what I have please respond below.