I have a couple of Datastores that create the value I want, but won't save the value correctly.
local DRBCstore = game:GetService("DataStoreService"):GetDataStore("RBCStore") game.Players.PlayerAdded:connect(function(player) local RBC = Instance.new("IntValue") RBC.Name = "RBCowns" RBC.Parent = player local key = "user-" .. player.userId local storeditems = DRBCstore:GetAsync(key) if storeditems then player.RBCowns.Value = storeditems[1] else local items = {player.RBCowns.Value} DRBCstore:SetAsync(key, items) print("RBCowns value: "..player.RBCowns.Value.."") end end) game.Players.PlayerRemoving:connect(function(player) local items = {player.RBCowns.Value} local key = "user-" .. player.userId print("RBCowns value: "..player.RBCowns.Value.."") DRBCstore:SetAsync(key, items) end)
This Datastore creates the value as intended, but does not save the value as intended, and only prints when the player leaves, instead of also printing when the player loads their value.
This next script is a LocalScript located in the Player's GUI. I don't know if that's what's causing it to fail, but this LocalScript is supposed to set the Value to what I want it to save as.
script.Parent.MouseButton1Click:Connect(function(click) local Tickets = game.Players.LocalPlayer.leaderstats.Tickets local owns = game.Players.LocalPlayer.RBCowns if Tickets.Value >= script.Parent.Price.Value then Tickets.Value = Tickets.Value - script.Parent.Price.Value owns.Value = 1 end end)
The value correctly shows as 1 when I view it in studio testing, but when I leave, it resets to 0 and doesn't save. I have tested it multiple times in an actual game environment, and it just won't save correctly.
I also have a Datastore for a value named Tickets. It increases daily, and works just fine. However, in that last script above, the value does decrease like intended, but won't save as that decreased value, and instead stays what it was before.
tl;dr- My values won't save, and I don't know why.