(Edit)
I tried a crude method of attaching the tool onto the viewmodel, it doesnt really work if you take the tool out in firstperson, as it just instantly falls through the map but if you equip it in third person and go into first person it works
Heres the code (In StarterCharacterScripts)
-- Variables
local Player = game:GetService("Players")["LocalPlayer"]
local Character = Player.CharacterAdded:Wait()
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local BaseViewModel = game.ReplicatedStorage.Stuff.Arms
local Tool = script.Parent.Parent
local ViewModel = if camera:FindFirstChild("ViewModel") then camera:FindFirstChild("ViewModel") else nil
local GripWeld = nil
local ConnectionTable = {}
local t = {}
-- Main
if not ViewModel then
ViewModel = BaseViewModel:Clone(); ViewModel.Name = "ViewModel"
ViewModel.Parent = camera
ViewModel:PivotTo(CFrame.new(0,math.huge,0))
end
-- Event Functions
Character.DescendantAdded:Connect(function(Obj)
if Obj:IsA("Weld") and Obj.Name == "RightGrip" then
GripWeld = Obj
end
end)
Tool.Equipped:Connect(function()
ConnectionTable["ToolEquipped"] = RunService.Heartbeat:Connect(function()
local Distance = (camera.CFrame.Position - camera.Focus.Position).Magnitude
if Distance <= .53 then
if GripWeld then
GripWeld.Part0 = ViewModel.RightArm
end
ViewModel:PivotTo(camera.CFrame)
else
if GripWeld then
GripWeld.Part0 = Character["Right Arm"]
end
ViewModel:PivotTo(CFrame.new(0,math.huge,0))
end
end)
end)
Tool.Unequipped:Connect(function()
if ConnectionTable["ToolEquipped"] then ConnectionTable["ToolEquipped"]:Disconnect() end
ViewModel:PivotTo(CFrame.new(0,math.huge,0))
end)ervice = game:GetService("RunService")
local Character = script.Parent
local camera = workspace.CurrentCamera
local BaseViewModel = game.ReplicatedStorage.Stuff.Arms
local ViewModel
local ConnectionTable = {}
local t = {}
-- Main
local ViewModel = BaseViewModel:Clone(); ViewModel.Name = "ViewModel"
ViewModel.Parent = camera
ViewModel:PivotTo(CFrame.new(0,math.huge,0))
-- Event Functions
Character.ChildAdded:Connect(function(Child)
if Child:IsA("Tool") and not t["Dead"] then
ConnectionTable["ToolEquipped"] = RunService.Heartbeat:Connect(function()
local Distance = (camera.CFrame.Position - camera.Focus.Position).Magnitude
if Distance <= .53 then
ViewModel:PivotTo(camera.CFrame)
else
ViewModel:PivotTo(CFrame.new(0,math.huge,0))
end
end)
end
end)
Character.ChildRemoved:Connect(function(Child)
if Child:IsA("Tool") and not t["Dead"] then
if ConnectionTable["ToolEquipped"] then ConnectionTable["ToolEquipped"]:Disconnect(); print(Child, "Unequipped") end
ViewModel:PivotTo(CFrame.new(0,math.huge,0))
end
end)