Add avatar clothes to viewmodel

helloo the problem i have with this is that it cant apply the players clothes on the arm of the viewmodel, there was a time that it worked but the problem was that you can see 2 tools while in first person, fixed it by making it invisible but now the clothes wont work anymore.

the code is here:
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local ViewModel = game.ReplicatedStorage.ViewModel:Clone()

local root = ViewModel:FindFirstChild(“HumanoidRootPart”)
local torso = ViewModel:FindFirstChild(“Torso”)

if root and torso then
local weld = Instance.new(“WeldConstraint”)
weld.Part0 = root
weld.Part1 = torso
weld.Parent = torso
torso.CFrame = root.CFrame
end

local humanoid = Instance.new(“Humanoid”)
humanoid.Name = “FakeHumanoid”
humanoid.Parent = ViewModel

local function CloneShirt()
local shirt = char:FindFirstChildOfClass(“Shirt”)
if shirt then
local shirtClone = shirt:Clone()
shirtClone.Parent = ViewModel
end
end

char:WaitForChild(“Head”)
char:WaitForChild(“Shirt”)
char:WaitForChild(“Torso”)

CloneShirt()

for _, armName in {“Left Arm”, “Right Arm”} do
local sourceArm = char:FindFirstChild(armName)
local vmArm = ViewModel:FindFirstChild(armName)
if sourceArm and vmArm then
vmArm.Color = sourceArm.Color
vmArm.Material = sourceArm.Material
end
end

local tool = char:WaitForChild(“Phone”)

local function MakeToolInvisible()
if tool and tool:FindFirstChild(“Handle”) then
tool.Handle.Transparency = 1
end
end

local function RestoreToolVisibility()
if tool and tool:FindFirstChild(“Handle”) then
tool.Handle.Transparency = 0
end
end

local function IsInFirstPerson()
local camera = game.Workspace.CurrentCamera
local head = char:FindFirstChild(“Head”)
if camera and head then
local cameraPosition = camera.CFrame.p
local headPosition = head.Position
local distance = (cameraPosition - headPosition).Magnitude
return distance < 1
end
return false
end

local function UpdateToolVisibility()
if IsInFirstPerson() then
MakeToolInvisible()
else
RestoreToolVisibility()
end
end

UpdateToolVisibility()

game:GetService(“RunService”).RenderStepped:Connect(function()
UpdateToolVisibility()
end)

Hi, can you tell me exactly what is viewmodel exactly?? is it a copy of the player character or what exactly, what are you using it for?

For the Viewmodels in my game, I’ve written a function that runs when the players CharacterAppearance has loaded.
player.CharacterAppearanceLoaded:Connect(function()

And all that function does is scan the player for both a BodyColors and a Shirt instance, if either is found, the code clones them over to the viewmodel(s).

This code is also ran whenever a new viewmodel is added.

player.CharacterAppearanceLoaded:Connect(function(character)
    if character:FindFirstChildOfClass("Shirt") then
        --// Clone shirt
    end
    if character:FindFirstChildOfClass("BodyColors") then
        --// Clone body colors
    end
end

Why not to use LocalTransparencyModifier ?

if you want to use classic shirts, and not layered clothing (custom meshes, NOT the clothing seen on the marketplace), then all you do is just:

local shirt = Instance.new("Shirt") -- or i think it was clothing bruh idk
shirt.Id = "shirtIdHere"
shirt.Parent = viewmodel

-- if your viewmodel has "Left Arm" and "Right Arm", they will now have sleeves
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.