Really stumped on why first person arms viewmodel not working properly

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.
image

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.

2 Likes

Update: issue is still persisting for me, if you can help please do, i still don’t understand why this is happening, i’ve asked all my friends and they still can’t figure it out.

I think we’d be able to help a bit more if we had the placefile or model.

My guess is that the “Right” and “Left” parts which dictate where the arm’s are placed are likely anchored and not welded to the weapon itself. It’s possible you haven’t noticed because they’re transparent? Beyond that I’d have to see the actual model itself.

Also, in the future this is probably a better question to send to me directly. I’m friendly, I promise! :grin:.

I know stuff about the structure of the view model and weapon etc that a casual reader wouldn’t know and I can also adjust the tutorial if your issue stems from an oversight in the original post. It’s a win win for everybody.

2 Likes

Thank you so much for responding! First off, I shall say that yes, Right and Left are the parts that (as you said in your post) that We were going to use the Cframe of the Parts “Left” and “right” in order in the viewmodel to have the arms, which is said in this line of code that you had in the post.

	-- get shoulder we are rotating
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;

Also, the rig and weapon are in ReplicatedStorage just like how you said to do it in the tutorial, stuff here. image

I just want to state that I’m doing it in a tool, but i don’t think that could be an issue, however it could be, since this is an issue i have never came across while working on anything related to tools. image

My arm rig is also done as the way you stated it previously on the post, as the arms should not be transparent, and not be anchored, and the only thing in the rig that is anchored is the head, which is also transparent along with the torso.

As a person who specializes in weapons (such as the bullet types, raycast/projectile) and this is my first time doing viewmodels, that’s why i was really stumped. if you want me to, i’ll gladly dm you on the devforums (only if you’re okay with it.)

edit: I can’t tell if this is an issue with the rig and weapons or not, but for some reason whilst going first person with the weapons it causes me to fling around, and all the items in the weapon are cancollide off and only left and right are anchored.

https://gyazo.com/75a074f2ffe5288d5b046d12e202a0e4

edit 2: yes, the issue was actually because i anchored the left and right items to the gun, rather than weld it. I fixed this, and it looks pretty well in my opinion.
https://gyazo.com/09cd7ba8f184e563ea6e5d18df45ebf1

However, all i really need to figure out is why is it when i go first person the arms fling me and how i’d go around to making the rig and weapon visible and invisible using tool.Equipped and tool.Unequipped.

Yes, you absolutely dm me on the devforums or discord, whatever is easier.

As for your collision issue, i believe the issue stems from having a humanoid in the view model. This causes automatic collision that to my knowledge overrides the cancollide property.

You may be able to fix this though by setting the humanoid state to physics or setting platform stand equal to true. Keep in mind i have not tested this, its just an initial guess at a solution.