How to make viewmodels out of the players arms? (again)

Yeah imma probably try and turn it into a viewmodel, and post the results here. (because I hate when they say “I found the solution” and don’t say the solution lol)

1 Like

code so far (not complete still need animations but im workin on that):

local player = game.Players.LocalPlayer
local character = player.Character

local id = player.UserId

local humanoidDesc = game.Players:GetHumanoidDescriptionFromUserId(id)

local viewmodel = game.ReplicatedStorage.Viewmodel:Clone()

viewmodel.Parent = workspace

viewmodel.Humanoid:ApplyDescription(humanoidDesc)

viewmodel["Left Leg"]:Destroy()
viewmodel["Right Leg"]:Destroy()

for _, part in viewmodel:GetDescendants() do
	if part:IsA("Accessory") then
		part:Destroy()
	end
	
	if part:IsA("Decal") then
		part:Destroy()
	end
end

viewmodel["Torso"].Transparency = 1
viewmodel["Head"].Transparency = 1

game["Run Service"].RenderStepped:Connect(function()
	
	viewmodel["Torso"].CanCollide = false
	viewmodel["Head"].CanCollide = false
	
	viewmodel["Left Arm"].CanCollide = false
	viewmodel["Right Arm"].CanCollide = false
	
	viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
end)
1 Like

code (with animation copying):

local player = game.Players.LocalPlayer
local character = player.Character

local id = player.UserId

local humanoidDesc = game.Players:GetHumanoidDescriptionFromUserId(id)

local viewmodel = game.ReplicatedStorage.Viewmodel:Clone()

local plrAnimator = character.Humanoid.Animator

local vmAnimator = viewmodel.Humanoid.Animator

local loadedAnimations = {}

viewmodel.Parent = workspace

viewmodel.Humanoid:ApplyDescription(humanoidDesc)

viewmodel["Left Leg"]:Destroy()
viewmodel["Right Leg"]:Destroy()

for _, part in viewmodel:GetDescendants() do
	if part:IsA("Accessory") then
		part:Destroy()
	end
	
	if part:IsA("Decal") then
		part:Destroy()
	end
end

viewmodel["Torso"].Transparency = 1
viewmodel["Head"].Transparency = 1

local function updateAnims() 
	for charAnim, Anim in pairs(loadedAnimations) do
		if charAnim.IsPlaying ~= Anim.IsPlaying then
			if charAnim.IsPlaying then
				Anim:Play()
			else
				Anim:Stop()
			end
		end
	end
end

game["Run Service"].RenderStepped:Connect(function()
	
	viewmodel["Torso"].CanCollide = false
	viewmodel["Head"].CanCollide = false
	
	viewmodel["Left Arm"].CanCollide = false
	viewmodel["Right Arm"].CanCollide = false
	updateAnims()
	viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
end)

plrAnimator.AnimationPlayed:Connect(function(AnimationTrack)
	-- imma put a viewmodel attribute like that one tutorial 
	
	--if AnimationTrack:GetAttribute("ViewmodelAnimation") ~= true then return end
	
	if not loadedAnimations[AnimationTrack] then
		
		loadedAnimations[AnimationTrack] = vmAnimator:LoadAnimation(AnimationTrack.Animation)
	end
end)


Fixed small bug with viewmodel collision

local player = game.Players.LocalPlayer
local character = player.Character

local id = player.UserId

local humanoidDesc = game.Players:GetHumanoidDescriptionFromUserId(id)

local viewmodel = game.ReplicatedStorage.Viewmodel:Clone()

local plrAnimator = character.Humanoid.Animator

local vmAnimator = viewmodel.Humanoid.Animator

local loadedAnimations = {}

viewmodel.Parent = workspace

viewmodel.Humanoid:ApplyDescription(humanoidDesc)

viewmodel["Left Leg"]:Destroy()
viewmodel["Right Leg"]:Destroy()

for _, part in viewmodel:GetDescendants() do
	if part:IsA("Accessory") then
		part:Destroy()
	end
	
	if part:IsA("Decal") then
		part:Destroy()
	end
end

viewmodel["Torso"].Transparency = 1
viewmodel["Head"].Transparency = 1

local function updateAnims() 
	for charAnim, Anim in pairs(loadedAnimations) do
		if charAnim.IsPlaying ~= Anim.IsPlaying then
			if charAnim.IsPlaying then
				Anim:Play()
			else
				Anim:Stop()
			end
		end
	end
end

viewmodel["Head"].CollisionGroup = "Viewmodel"
viewmodel["Torso"].CollisionGroup = "Viewmodel"
viewmodel["Left Arm"].CollisionGroup = "Viewmodel"
viewmodel["Right Arm"].CollisionGroup = "Viewmodel"

game["Run Service"].RenderStepped:Connect(function()
	
	viewmodel["Torso"].CanCollide = false
	viewmodel["Head"].CanCollide = false
	
	viewmodel["Left Arm"].CanCollide = false
	viewmodel["Right Arm"].CanCollide = false
	updateAnims()
	viewmodel.Head.CFrame = workspace.CurrentCamera.CFrame
end)

plrAnimator.AnimationPlayed:Connect(function(AnimationTrack)
	-- imma put a viewmodel attribute like that one tutorial 
	
	--if AnimationTrack:GetAttribute("ViewmodelAnimation") ~= true then return end
	
	if not loadedAnimations[AnimationTrack] then
		
		loadedAnimations[AnimationTrack] = vmAnimator:LoadAnimation(AnimationTrack.Animation)
	end
end)

character.DescendantAdded:Connect(function(obj)
	
	if (obj:IsA("Weld") and obj.Name == "RightGrip") then
		wait()
		obj.Part0 = viewmodel[obj.Part0.Name]
	end
end)

This was because when I used a trench gun model (trying to make this idiot-proof, everybody), when you shot at your feet, you went flying and the viewmodel broke. I fixed this by changing the viewmodel’s collision group.

Note to self: Release cleaned up code to community tutorials later.