I’ve been working on a game and Data Storing has been a problem with me for a while. It might be some setting I haven’t enabled: Something so my scripts change a value then have that same changed value be saved by my Data Store. or it could also just be the Data Store script itself. The weirdest thing is that if I go into a game and use the developer console, to change the value, it saves it.
Script:
local DataStoreService = game:GetService(“DataStoreService”)
local myDataStore1 = DataStoreService:GetDataStore(“myDataStore1”)
game.Players.PlayerAdded:Connect(function(player)
local Stats = Instance.new(“Folder”)
Stats.Name = “Stats”
Stats.Parent = player
local cash = Instance.new(“IntValue”)
cash.Name = “Cash”
cash.Parent = Stats
local data
local success, errormessage = pcall(function()
data = myDataStore1:GetAsync(player.UserId…"-cash")
end)
if success then
cash.Value = data
print(“Player Data successfully loaded!”)
else
print(“There was an error whilst getting your data”)
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errormessage = pcall(function()
myDataStore1:SetAsync(player.UserId…"-cash",player.Stats.Cash.Value)
end)
if success then
print(“Player Data successfully saved!”)
else
print(“There was an error when saving data”)
warn(errormessage)
end
end)
Hopefully you guys can help me! Thanks.