I’ve followed these two tutorials:
devforum.roblox.com/t/easyfirstperson-drag-and-drop-first-person-view-models/1198782 (arm tutorial)
devforum.roblox.com/t/how-to-animate-tool-parts-guns-knifes-etc/359484 (animation tutorial)
and ended up with a pretty nice product but I ran into a problem. The tool stays the same place while the arms move but of the way I animated the tool. Is there a way I can fix this while still keeping the same animation?
Video of the issue:
https://gyazo.com/e5c51105860a571390a38d2cdc9bfd87
Thanks for your time!
the script would be nice.
Whoops I forgot about that!
Here is the script for making the arms follow the cursor / camera movement:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.Character or Player.CharacterAdded:Wait()
local Torso = Character:WaitForChild("Torso") :: BasePart
local RightArm = Character:WaitForChild("Right Arm") :: BasePart
local LeftArm = Character:WaitForChild("Left Arm") :: BasePart
local LeftShoulder = Torso:WaitForChild("Left Shoulder") :: Motor6D
local RightShoulder = Torso:WaitForChild("Right Shoulder") :: Motor6D
local Humanoid = Character.Humanoid :: Humanoid
local OffsetMouseYAngle = math.rad(15)
RunService.RenderStepped:Connect(function()
if Humanoid.Sit then return end
local mouseYAngle = math.asin((Mouse.Hit.Position - Mouse.Origin.Position).Unit.Y) - OffsetMouseYAngle
if LeftShoulder and LeftArm then
LeftShoulder.C0 = CFrame.new(-1, 0.5, -0.2) * CFrame.Angles(math.rad(70) + mouseYAngle, 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(120) + mouseYAngle, math.rad(90), math.rad(-104))
end
end)
The animations use a motor 6D located in the torso to attach to the character and do not have a handle so I can animated the tool in more detail. There is more info on this in the animation tutorial.
Unfortunately fixing this issue is complicated as you are using 2 different systems, and I cant really explain much about it. The trick here is that you would want to replicate the weld system used on the character to the viewmodel. So once there is a viewmodel, you would want to change both the character and viewmodel’s weld properties.
I advised to just create your own viewmodel/first person system, as this is a hacky solution
Here is my system without modifying the viewmodel script:
Server Script
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local toolGrip = Instance.new("Motor6D")
toolGrip.Name = "ToolGrip"
toolGrip.Parent = char.Torso
char.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
local bodyAttach = child:FindFirstChild("BodyAttach", true)
if bodyAttach then
toolGrip.Part0 = char.Torso
toolGrip.Part1 = bodyAttach
end
end
end)
char.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
toolGrip.Part1 = nil
end
end)
end)
end)
Local Script on StarterCharacterScripts
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local torso = character:FindFirstChild("Torso")
local viewmodel
local camera = workspace.CurrentCamera
function setWelds()
print("viewmodel")
local toolGrip = torso:FindFirstChild("ToolGrip")
local toolGripVM = viewmodel.HumanoidRootPart:FindFirstChild("ToolGrip")
if not toolGripVM then
toolGripVM = Instance.new("Motor6D")
toolGripVM.Name = "ToolGrip"
toolGripVM.Parent = viewmodel.HumanoidRootPart
end
if toolGripVM and toolGrip then
print("toolgrip")
if not toolGrip.Part1 and character:FindFirstChildWhichIsA("Tool") then
toolGrip:GetPropertyChangedSignal("Part1"):Wait()
end
local bodyAttach = toolGrip.Part1
if bodyAttach then
print("bodyattach")
toolGrip.Part1 = nil
toolGripVM.Part0 = viewmodel.HumanoidRootPart
toolGripVM.Part1 = bodyAttach
end
end
end
function resetWelds()
local toolGrip = torso:FindFirstChild("ToolGrip")
local toolGripVM = viewmodel.HumanoidRootPart:FindFirstChild("ToolGrip")
local bodyAttach
if toolGripVM then
bodyAttach = toolGripVM.Part1
toolGripVM.Part1 = nil
end
if torso then
if toolGrip then
toolGrip.Part1 = bodyAttach
toolGrip.Part0 = torso
end
end
end
camera.ChildAdded:Connect(function(child)
if child.Name == "Viewmodel" and character then
viewmodel = child
setWelds()
end
end)
camera.ChildRemoved:Connect(function(child)
if child.Name == "Viewmodel" and character then
resetWelds()
end
end)
character.ChildAdded:Connect(function(child)
if child:IsA("Tool") then
if viewmodel and viewmodel.Parent == camera then
setWelds()
end
end
end)
character.ChildRemoved:Connect(function(child)
if child:IsA("Tool") then
if viewmodel and viewmodel.Parent == camera then
resetWelds()
end
end
end)