Basically i’m really new to oop and i created a system where i store all of the pets properties in the oop like adding the multiplier, name and model in there but i don’t know how i can get that table or pet from another script
local Pets = {}
Pets.__index = Pets
function Pets.new(Name, Model, Multiplier)
local NewPet = {}
setmetatable(NewPet, Pets)
NewPet.Name = Name
NewPet.Model = Model
NewPet.Multiplier = Multiplier
return NewPet
end
newpet = Pets.new("Cat", script.Pets.Cat, 2)
return Pets
I’m a bit confused on what you’re planning to do with the object returned, but from what I can understand you’d probably be able to use a ModuleScript which contains all the players’ data (example: the key is set to the Player object, and the value is the data stored)
So then, when you need to access the data, you can do something like this:
local playerData = PlayerDataModule[Player]
for _, pet in playerData.Pets do
-- pet is the object made by the module
end
And for storing, you could have a Players.PlayerAdded connection such as this:
local function onPlayerAdded(player: Player)
local playerData = {
Pets = {}
}
-- do something to initialize the playerData table and put the Pet objects in
-- playerData.Pets
PlayerDataModule[player] = playerData
end
Just make sure to remove the entry from the module once player leaves… It’ll leak memory otherwise