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
There are no errors in the output.\
Any help would be appreciated.
Thanks for reading ![]()