Cloning a player while in a seat not working

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)

photoscripterror

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.

1 Like

This means you’re illegally trying to access a nil object with .Parent, can you please indicate which line of code is line 18?

1 Like

Line 18 is when I’m trying to parent the Clone to the photofolder. It cant clone because archivable for the player remains false.

1 Like

Well whatever your trying to parent it too doesn’t exist

1 Like

The parent exists, its the clone of the object im trying to parent that doesn’t.

1 Like

Did you try just using v.Occupant:Clone().Parent =

1 Like

Never mind that wouldn’t make any sense

1 Like

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.

3 Likes

It would clone the humanoid. image

1 Like

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()
2 Likes

The issue is making it archivable. When I do seat.Occupant.Parent.Archivable = true it remains false.

1 Like

Ok, I’ll try that now, thanks.

1 Like

Another potential solution would be to fetch the Player’s Character Model using a Roblox Async:

local Players = game:GetService("Players")
local Model = Players:GetCharacterAppearanceAsync(UserID)
2 Likes

It still errors sadly. Archivable remained false throughout. image

1 Like

Ok, I’ll look further into that. I’ve never used it before.

1 Like

How about you remove the .Parent and see if it prints anything?

2 Likes

Prints nothing. I’d assume cause it has no Parent so technically doesn’t exist.

Needs a slight bit of tweaking but works! Thanks for your help, much appreciated. image

1 Like