Hi guys, i have a problem with datastores. I made my dataStore for a value which i called progress. It worked and it saved the value, but after changing it - the old value is still showing. I have no idea what is causing this. I’m new at the dataStores so i have no idea what to do. Here is the script:
local Player = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local database = DataStoreService:GetDataStore("data")
local sessionData = {}
function playerAdded(player)
local Folder = Instance.new("Folder")
Folder.Name = "ProgressFolder"
Folder.Parent = player
local progress = Instance.new("NumberValue")
progress.Name = "Progress"
progress.Parent = Folder
progress.Value = 0
local success = nil
local plrData = nil
local attempt = 1
repeat
success, plrData = pcall(function()
return database:GetAsync(player.UserId)
end)
attempt+= 1
if not success then
warn(plrData)
task.wait(3)
end
until success or attempt == 5
if success then
print("Connected to data")
if not plrData then
print("Assigning deafult data")
plrData = {
["Progress"] = 0
}
end
sessionData[player.UserId] = plrData
else
warn("Unable to get data for ", player.Name)
player:Kick("ERROR: " .. player.Name .. "_DATA UNABLE TO LOAD. TRY LATER")
end
progress.Value = sessionData[player.UserId].Progress
progress.Changed:Connect(function()
sessionData[player.UserId].Progress = progress.Value
end)
end
Player.PlayerAdded:Connect(playerAdded)
function playerLeaving(player)
if sessionData[player.UserId] then
local success = nil
local errorMsg = nil
local attempt = 1
repeat
success, errorMsg = pcall(function()
database:SetAsync(player.UserId, sessionData[player.UserId])
end)
attempt+= 1
if not success then
warn(errorMsg)
task.wait(3)
end
until success or attempt == 5
if success then
print("Saved data for", player.Name)
else
warn("unable to save for", player.Name)
end
end
end
Player.PlayerRemoving:Connect(playerLeaving)
Also if you need to ask me questions - go ahead, i will try to answer them.