I setup a module to clone the players character and keep a copy for reference.
Relevant part of that script:
local function CloneCharacter(character)
character.Archivable = true
local Clone = character:Clone()
character.Archivable = false
return Clone
end
function module.KeepOriginalCharacter(player)
local PlayerCache = Cache:WaitForChild(player.Name)
if PlayerCache then
-- check if OriginalCharacter already exists
if not PlayerCache:FindFirstChild("OriginalCharacter") then
-- wait for appearance (from Roblox sample)
local function WaitForAppearance()
local loaded = player:HasAppearanceLoaded()
while not loaded do
loaded = player:HasAppearanceLoaded()
task.wait()
end
end
WaitForAppearance()
-- clone/keep character
local OriginalCharacterClone = CloneCharacter(player.Character)
OriginalCharacterClone.Name = "OriginalCharacter"
OriginalCharacterClone.Parent = PlayerCache
end
end
end
Later, another part of the module clones needed parts from that OriginalCharacter to a StarterCharacter to be used by the player.
Relevant part of that section:
local ReferenceCharacter = PlayerCache:FindFirstChild("OriginalCharacter")
if ReferenceCharacter:FindFirstChild("Pants") then
local pantsClone = ReferenceCharacter.Pants:Clone()
pantsClone.Parent = StarterCharacterClone
else
warn("Pants not found", player)
end
While testing in Roblox I sometimes get the warning “Pants not found.”
I have tried everything I can think of. My latest attempt was to search Roblox and see how they are waiting for the appearance to load.
The wait for appearance (from Roblox sample)
is from the Roblox documentation, but it does not fix the issue.
Any ideas on what I am doing wrong?