When I test my game in studio and change my stats, to see if certain aspects of the game are working, they don’t seem to always save when I hit stop. I’m not sure what the issue is since it does work about 50% of the time and I verified that it is running all the way through since it prints “data saved”. I haven’t tested the saving mechanism in a real server yet so I’m wondering if this is just a glitch that only occurs in studio. Either way if anyone else has ran into this problem or knows a solution my code is below.
Thanks
game:BindToClose(function()
local players = Players:GetPlayers()
for _, player in pairs(players) do
local Key = player.UserId
local DataTable = {
cash = leaderstats.Cash.Value,
day = leaderstats.Day.Value,
pineapple = ingredients.Pineapple.Value,
olive = ingredients.Olive.Value,
mushroom = ingredients.Mushroom.Value,
spinach = ingredients.Spinach.Value,
bananapepper = ingredients.BananaPepper.Value,
ham = ingredients.Ham.Value,
chicken = ingredients.Chicken.Value,
bacon = ingredients.Bacon.Value,
pepper = ingredients.Pepper.Value
}
MyDataStore:SetAsync(Key, DataTable)
end
print("Data saved")
end)
Update: When I change the value of Pineapple I get this error in the output. Anyone know what this means?
[ServerScriptService.Main.Leaderboard/Save:142: attempt to index function with ‘Pineapple’]