Move array table to another array?

I’m wondering how I could move GUID and Type from Inventory to Equipped?

GUID is a table.
Type is a string in GUID.

local function EquipPet(Player, Type, GUID)
	if PlayerSessionData[Player].Pets.Inventory[GUID] then
		if DataService:Equipped(Player, "MaxEquipped") >= DataService:Equipped(Player, "CurrentEquipped") then
			PlayerSessionData[Player].Pets.Inventory[GUID] = nil -- remove "GUID" from inventory.
			PlayerSessionData[Player].Pets.Equipped = GUID[Type] -- add "GUID" into equipped.
		end
	else
		return
	end
end
1 Like

You can try using table.move. It moves a value from one table to another.

If you don’t know what that is, look at the tables documentation on the developer hub.

1 Like

Is equipped a table? 30 charsss

Yes, both inventory and equipped are tables :slight_smile:

“This is 30 characters.”

To add to that table you can do this:

PlayerSessionData[Player].Pets.Equipped[#PlayerSessionData[Player].Pets.Equipped + 1] = GUID[Type]

Hopefully that helps. It adds it completely to the table.

2 Likes

It doesn’t work for some reason :thinking: I tried to print the equipped pets, but it does not print.

PlayerSessionData[Player].Pets.Inventory[GUID][Type] = nil
PlayerSessionData[Player].Pets.Equipped[#PlayerSessionData[Player].Pets.Equipped + 1] = GUID[Type]
delay(1,function() --print.
	for i,v in pairs(PlayerSessionData[Player].Pets.Equipped) do
		print(i,v)
	end
end)

@quamatic Nvm, I figured it out. Thanks for the help, I appriciate it :pray:

Solution:

PlayerSessionData[Player].Pets.Inventory[GUID] = nil
PlayerSessionData[Player].Pets.Equipped[GUID] = {Type}