I’m trying to write a script that gets the player’s character when they load in and clones all the player’s limbs and hats and then creates a MeshPart for each limb/hat and changes the size, position, and MeshId to match. Then I want to weld each mesh to the corresponding part of the player.
I’d managed to write a (messy) script that creates a MeshPart for each limb and welds it to the character, but I cannot figure out how to change the MeshID as it keeps returning the same error:
“The current thread cannot write ‘MeshId’ (lacking capability NotAccessible)”
Attached below are my script, which is a ServerScript located in ServerScriptService, as well as two videos showing the results of the script. One with the lines that change the MeshIds removed and one with them kept in.
Please forgive my sloppy code as I am not the best at scripting. Any help is appreciated.
local Players = game:GetService("Players")
local AssetService = game:GetService("AssetService")
local LocalPlr = Players.LocalPlayer
Players.PlayerAdded:Connect(function(Plr)
Plr.CharacterAdded:Connect(function(Char)
print("Character Added")
for _, v in pairs(Char:GetDescendants()) do
if v:IsA("BasePart") and v.Name ~= "HumanoidRootPart" and v.Name ~= "Handle" then
local NewMesh = Instance.new("MeshPart")
NewMesh.Name = "FakeLimb"
NewMesh.Size = v.Size
NewMesh.Parent = Char
NewMesh.CanCollide = false
NewMesh.Position = v.Position
NewMesh.Transparency = 0.5
print("Fake Mesh Added")
local NewWeld = Instance.new("WeldConstraint")
NewWeld.Parent = NewMesh
NewWeld.Name = "FakeMeshWeld"
NewWeld.Part0 = NewMesh
NewWeld.Part1 = v
print("Weld Added")
if v.Name == "RightArm" or v.Name == "LeftArm" or v.Name == "RightLeg" or v.Name == "LeftLeg" or v.Name == "Torso" then
NewMesh.MeshId = "rbxassetid://2828256740"
end
if v.Name == "Head" then
NewMesh.MeshId = "rbxassetid://5591363797"
NewMesh.Name = "FakeHead"
end
end
if v:IsA("CharacterMesh") then
local NewMesh = Instance.new("MeshPart")
NewMesh.Name = "FakeLimb"
NewMesh.Size = v.Size
NewMesh.Parent = Char
NewMesh.CanCollide = false
NewMesh.Position = v.Position
NewMesh.Transparency = 0.5
NewMesh.MeshId = v.MeshId
print("Fake Limb Added")
local NewWeld = Instance.new("WeldConstraint")
NewWeld.Parent = NewMesh
NewWeld.Name = "FakeMeshWeld"
NewWeld.Part0 = NewMesh
NewWeld.Part1 = v.BodyPart
print("Weld Added")
end
if v.Name == "Handle" then
local OldMesh = v:FindFirstChild("SpecialMesh") or v:FindFirstChild("Mesh")
local NewMesh = Instance.new("MeshPart")
NewMesh.Name = "FakeMesh"
NewMesh.Size = v.Size
NewMesh.Parent = Char
NewMesh.CanCollide = false
NewMesh.Position = v.Position
NewMesh.Transparency = 0.5
NewMesh.MeshId = OldMesh.MeshId
print("Fake accessory added")
local NewWeld = Instance.new("WeldConstraint")
NewWeld.Parent = NewMesh
NewWeld.Name = "FakeMeshWeld"
NewWeld.Part0 = NewMesh
NewWeld.Part1 = v
print("Accessory weld added")
end
end
end)
end)