Hi! My problem is that data is just not saving eventhough OnUpdate fires and when I print the data inside it prints as expectedly. Also every other key I change with that purchase like money, gets updated but not saved upon rejoining. Please help! (not testing in studio)
local datastore2 = require(script.Parent:WaitForChild("DataStore2"))
datastore2.Combine("DATA", "money", "weapon")
local weapons = {
["CandyCane"] = {10000000000, false}, -- PRICE, OWNED
["DoubleRevolver"] = {1230, false},
["DoubleRifle"] = {5280, false},
["GoldenRevolver"] = {590, false},
["Minigun"] = {1000000000000, false},
["SingleRifle"] = {1850, false},
["GoldenRifle"] = {2660, false}
}
coroutine.wrap(function() -- new thread so I can run this and OnUpdate()
someInvoke.OnServerInvoke = function(plr, gun) -- invoke when buying guns, gun - gun.Name
local weaponStore = datastore2("weapon", plr)
datastore2("money", plr):Increment(-price, 0)
weaponStore[gun][2] = true
datastore2("weapon", plr):Set(weaponStore) -- seting owned to true
game:GetService("ServerStorage").Weapons[gun]:Clone().Parent = plr.Character
print("done") -- it prints done
return 1
end
end)
game:GetService("Players").PlayerAdded:Connect(function(plr)
local weaponStore = datastore2("weapon", plr)
print(table.unpack(weaponStore:GetTable(weapons)["GoldenRevolver"])) -- always prints 590, false
weaponStore:OnUpdate(function()
print(weaponStore:GetTable(weapons)["GoldenRevolver"][2]) -- after I do Set() it prints true
end)
end)