Find descendant copy of :Clone()'d model

I want to find the corresponding seat instance that the player was sitting in, but in the Clone version

local Original = workspace.Model
local SeatPart = Players.LocalPlayer.Character.Humanoid.SeatPart -- the SeatPart is descendant of Original
local Clone = Original:Clone()
local ClonedSeatPart = ?????

What do you mean by that? Can you be more specific?

If SeatPart is a descendant of workspace.Model then you can index the SeatPart in the Clone.

True, but my model is basically a tank with multiple turrets with multiple seats (GunnerSeat, etc) and I wouldnt know the exact turret the player was in

Use a for parameter to go through all the seats, and find which one the player’s sitting on?

but some seats have the same names, i cant do

for i,v in ipairs(Clone:GetDescendants()) then
   if v:IsA("VehicleSeat") then
      if v.Name == SeatPart.Name then
         ...
         return
   end
end

as that would do it for the first seat it finds
Edit:
εικόνα
This is how it looks like
For example the SeatPart of the humanoid would be Model.Turrets.Turret1.GunnerVehicleSeat but the method above wont work

Check if someone’s sitting on that seat.

for i,v in ipairs(Clone:GetDescendants()) then
   if v:IsA("VehicleSeat") and v.Occupant ~= nil then
      if v.Name == SeatPart.Name then
         ...
         return
   end
end

@JohnPlayzRoblox421
Can I get an explanation as to what you’re trying to do? I’m so confused.

1 Like

I edited my previous message
Also if I clone the tank while the player is sitting in a seat, the cloned tank’s seat wouldn’t have an occupant right?

Are you trying to transfer the player to the cloned seat, and in that exact seat?

1 Like

Well not exactly that, I just want to store that exact seat in a variable

Alright, then.

You can make a function that runs every time a player sits downs or leaves their seat, then that seat can be stored in a variable.

When you clone, you simply use the variable to find that seat the player sat on.

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        local currentSeat = nil
        character.Humanoid:GetPropertyChangedSignal("Sit"):Connect(function()
        if character.Humanoid.Sit == true then
            for _,seat in pairs(original:GetDescendants()) do
                if seat:IsA("VehicleSeat") and seat.Occupant ~= nil and seat.Occupant == character.Humanoid then
                    currentSeat = seat
                end
            end
        else
            currentSeat = nil
        end
    end)
end)

This only tracks the original car, not the clone. You can use the variable to check inside the clone for that seat though.

1 Like

Im sorry for not being clear, I meant Im trying to find the seat that Corresponds to the seat the humanoid was sitting on in the Original model, in the Clone’d model.
If the humanoid was sitting in the Original.Turrets.Turret1.GunnerVehicleSeat, then I want to find the Clone.Turrets.Turret1.GunnerVehicleSeat

That’s what my code partially does.

You want to get that variable of the seat in the original, then find it in the clone.

1 Like

Can you elaborate on how do this? Sorry my brain not braining today

You need to make a function that checks whenever your player sits down, and you can then get that seat, and store it in a variable.

When you clone, you can use that variable to then find the exact seat in the clone.

Read it out slowly if you don’t properly understand.

humanoid:GetPropertyChangedSignal("Sit")

You can use this to find out whenever the Sit value is set to true or false.

1 Like

I understand what you mean, problem is idk if that’s gonna work because

local SeatPart = Humanoid.SeatPart
local seat = Original.Seat -- basically the previous variable
print(SeatPart == seat) -- true

for i,v in ipairs(Clone:GetDescendants()) do
   if v:IsA("VehicleSeat") and v.Name == SeatPart.Name then -- This if statement will be true, but there are a lot of seats with same name as the Humanoid.SeatPart.Name, running the code over
       if v == SeatPart then -- false
             
       end
   end
end

It’s because your code only runs once. That’s why I mentioned to run a function every time a Humanoid sits down.

1 Like

Im sorry for not providing more detail, im new on posting on devforum, but with your insight I was able to think of a solution

for i, OGPart in ipairs(Original) do
   if v:IsA("VehicleSeat") then
      for i, ClonePart in ipairs(Clone) do
         if v:IsA("VehicleSeat") then
            if OGPart.Occupant ~= nil and OGPart.Name == ClonePart.Name and OGPart.Parent.Name == ClonePart.Parent.Name then -- since the parents have different names this is possible
                
            end
         end
      end
   end
end

Thanks for the help

You can mark a comment as a solution.

1 Like