Hello, I have an issue with trying to Get and Saving data.
When A player joins the game This code runs
local function CreateLeaderstats(plr)
local statsFolder = Instance.new("Folder")
statsFolder.Name = "leaderstats"
statsFolder.Parent = plr
local Money = Instance.new("IntValue")
Money.Name = "Money"
Money.Parent = statsFolder
local TotalAnimals = Instance.new("IntValue")
TotalAnimals.Name = "TotalAnimals"
TotalAnimals.Parent = statsFolder
local DebounceTime = Instance.new("IntValue")
DebounceTime.Name = "DebounceTime"
DebounceTime.Parent = statsFolder
local CurrentAnimal = Instance.new("ObjectValue")
CurrentAnimal.Name = "CurrentAnimal"
CurrentAnimal.Parent = statsFolder
local PlrData = DataStore:GetAsync(plr.UserId.."stats")
if PlrData then
--Add all stats here
--If the PlrData index is nil it will Default to a value as the Default Value
Money.Value = PlrData[1] or 0
TotalAnimals.Value = PlrData[2] or 0
DebounceTime.Value = PlrData[3] or 5
CurrentAnimal.Value = PlrData[4] or game.ReplicatedStorage.Animals.Chicken
print("Loaded Data Successfully")
else
SaveData(plr) --This function saves data
end
Which is standard for a dataStore, But I have Animals in ReplicatedStorage that have their own Individual Values.
And I want to save these values.
And the other thing is that when I press a button it will spawn an animal, and when the animal is finished animating, it will give you money, exp, and The TotalAnimals value will increase, but when I increase my money I need to get the Animalvalue from the animal that spawned, and same thing with the exp. If anyone can help me with this that would be great, Thanks In Advance!
EDIT: I was also thinking of hardcoding the values into the animals, but I still need to save the values.