I hope I make sense. Lets start with the basic.
you enter a game with 100 Gold,
5 Strawberries and 2 Gold Strawberries. Nothing else.
Simple, we got 100 bucks and 7 Produce. That data is set up and then saved. But once I leave and come back, the numbers are all swapped.
You enter a game with 2 Gold,
100 Strawberries and 0 Gold Strawberries. Nothing else. (You didn’t sell or make any new produce before).
I know It HAS to be this script below because when I disable it; the game plays fine. All the mechanics and functions work properly.
(It wouldn’t save But) I would still have my 100 Gold, 5 Strawberries and 2 Golden Strawberries. And if I was to grow and sell more Strawberries/Golden Strawberries, their produce will correctly add up on the chart. (100 gold, 6 Strawberries, 3 Gold Strawberries. Assuming I harvested 1 from each plant).
Now idk if it’s maybe the order in which this script is coded. But I’m just confused.
Script: (I’m getting no errors that I can directly see, Unless there is a way to see errors In public games) It’s just for some reason, jumping up the values every time you enter the game.
local ds = game:GetService("DataStoreService"):GetDataStore("SaveData")
game.Players.PlayerAdded:Connect(function(plr)
wait()
local plyKey = "id_"..plr.UserId
local saveStraw = plr.ProduceNumberFolder.StrawberryCount
local saveGoldStraw = plr.ProduceNumberFolder.GoldStrawCount
local saveCarrot = plr.ProduceNumberFolder.CarrotCount
local savePotato = plr.ProduceNumberFolder.PotatoCount
local saveCabbage = plr.ProduceNumberFolder.CabbageCount
local saveSpinach = plr.ProduceNumberFolder.SpinachCount
local saveSpringOn = plr.ProduceNumberFolder.SpringOnionCount
local saveLettuce = plr.ProduceNumberFolder.LettuceCount
local saveMoney = plr.MoneyFolder.Gold
local GetSaved = ds:GetAsync(plyKey)
if GetSaved then
saveStraw.Value = GetSaved[1]
saveGoldStraw.Value = GetSaved[2]
saveCarrot.Value = GetSaved[3]
savePotato.Value = GetSaved[4]
saveCabbage.Value = GetSaved[5]
saveSpinach.Value = GetSaved[6]
saveSpringOn.Value = GetSaved[7]
saveLettuce.Value = GetSaved[8]
saveMoney.Value = GetSaved[9]
else
local SavingNumbers = {
saveStraw.Value,
saveGoldStraw.Value,
saveCarrot.Value,
savePotato.Value,
saveCabbage.Value,
saveSpinach.Value,
saveSpringOn.Value,
saveLettuce.Value,
saveMoney.Value}
ds:GetAsync(plyKey,SavingNumbers)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync("id_"..plr.userId,{
plr.ProduceNumberFolder.GoldStrawCount.Value,
plr.ProduceNumberFolder.StrawberryCount.Value,
plr.ProduceNumberFolder.CarrotCount.Value,
plr.ProduceNumberFolder.PotatoCount.Value,
plr.ProduceNumberFolder.CabbageCount.Value,
plr.ProduceNumberFolder.SpinachCount.Value,
plr.ProduceNumberFolder.SpringOnionCount.Value,
plr.ProduceNumberFolder.LettuceCount.Value,
plr.MoneyFolder.Gold.Value
})
end)
PLEASE NOTE: the only produce working and implemented in the game are Strawberries, Golden Strawberries, Carrots and Cabbages. None of the other values (Like Potato, Spinach etc) have actual data. I assume If I had all the produce coded and added, I’d still have the issue stated at the top of this post.
Any help is appreciated because I’ve spent the last 5 hours trying to figure it out. The closest I got to was figuring out that it had to be the save Data script.