I am trying to get a players character and duplicate it into a viewportframe located in ReplicatedStorage which will then be sent to the PlayerGui later on.
When I have been hitting the part to run the function it sends an error stating it index is nil with Parent which I believed is due to the part being unarchived as it is a player. Though I made it archivable, it isn’t picking that up in the script.
I have looked around on the devhub and devforum but am unable to find a similar issue. I have tried duplicating the player when the :PlayerAdded function runs which works so I know its not the code doing it, however after that trying to Clone the player is not possible.
The code I am using is below.
local PhotoFolder = script.PhotoFolder.Value
local PhotosTaken = script.PhotosTaken
local Hitter = script.Hitter.Value
Hitter.Touched:Connect(function(hit)
wait()
if (hit.Name == ("Trigger")) then
local PhotoX = PhotoFolder.PhotoX
local Clone = PhotoX:Clone()
Clone.Parent = PhotoFolder
PhotoFolder.PhotoX.Name = ("Photo"..PhotosTaken.Value.."")
hit.Parent.Parent.Parent:Clone().Parent = PhotoFolder["Photo"..PhotosTaken.Value..""].Photo
for i,v in pairs(hit.Parent.Parent.TrainPart1.Seats:GetChildren()) do -- gets seats in train
if v.Occupant ~= nil then -- checks if any occupant in seat
v.Occupant.Parent.Archivable = true
v.Occupant.Parent:Clone().Parent = PhotoFolder["Photo"..PhotosTaken.Value..""].Photo
v.Occupant.Parent.Archivable = false
end
end
PhotosTaken.Value = (PhotosTaken.Value + 1)
end
end)
This script is being ran in ServerScriptStorage and is a normal Script.
If you require any more info to try and help solve this issue I’m having just say what you need below and I’ll get it to you as soon as possible. Thanks for any help anyone may be able to give.
Did you try to set Archivable property of the character model and it’s descendants to true? Because otherwise calling :Clone() on it will not return anything.
You could use Occupant.Parent, that would do the trick as long as you set Archivable to true. Simple for loop will take care of that
EDIT:
local Occupant = v.Occupant.Parent
Occupant.Archivable = true
for _, p in next, Occupant:GetDescendants() do
p.Archivable = true
end
local Clone = Occupant:Clone()