Expressive output misleading

Simple and clear; I’m making a pet system. 3 days I’ve been stuck on this bug, either wit my code or lua.

I can’t define tables properly or use table.insert properly. Even metatables aren’t working out with me and I’m using the Dev Hub example.

Here is my code:

PetSystem.lua (modulescript)

-- made by recanman
local ps = {}

local ds2 = require(1936396537) -- ds2 module
local endResult = {}

local function calculateChances(chances)
	endResult = {}
	
	for _, data in pairs(chances) do
		for i = 1, data.Chance, 1 do
			table.insert(endResult, data.Type)
		end
	end
	
	return endResult[math.random(1, #endResult)]
end

function ps:BuyPet(plr, eggName)
	if (plr.leaderstats.Coins.Value - game.ReplicatedStorage.Assets.Eggs[eggName].Settings.Cost.Value >= 0) then
		plr.leaderstats.Coins.Value -= game.ReplicatedStorage.Assets.Eggs[eggName].Settings.Cost.Value
		
		local rarity = calculateChances(require(game.ReplicatedStorage.Assets.Eggs[eggName].Settings))
		local chosenPet = game.ReplicatedStorage.Assets.Eggs[eggName].Pets[rarity]:GetChildren()[math.random(1, #game.ReplicatedStorage.Assets.Eggs[eggName].Pets[rarity]:GetChildren())].Name
		
		local petsDs = ds2("Pets", plr)
		local inventory = petsDs:Get({})
		
		local layout = {PetName = "New Pet", PetType = chosenPet, PetRarity = rarity, PetLevel = 1, PetXP = 0}
		
		table.insert(inventory, layout)
		
		print(inventory)
		
		petsDs:Set(inventory)
		
		return true
	else
		return false
	end
end

return ps

So apparently, the table does get defined properly, but then something else happens when I print it.
Defining it

Printing it

There are no errors in the output.\

Any help would be appreciated.
Thanks for reading :slightly_smiling_face:

I don’t understand what you’re trying to achieve, nor what the issue is.

You’re printing inventory, but your first gif references layout? What is ds2?

ds2 most likely stands for DataStores2.

2 Likes

Actually, I was printing layout

If you run a code snippet that prints out contents of inventory, ie;

for i,v in pairs(inventory[1]) do
    print(i,v)
end

You will see that inventory properly populates with a ‘layout’. The expressive output window is misleading when it does not show this.

2 Likes

The issue is that the tables don’t print properly

@jrelvasthat is correct

Hmm, really? Looks like thats a bug to report to roblox, exprerssive outp\ut windows is misleading. I will try it out now.