#datastore problem.png

4 messages · Page 1 of 1 (latest)

worthy orbit
#

local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("Test")

local function saveData(player)
local tableToSave = {
player.leaderstats.Clicks.Value;
player.leaderstats.Rebirths.Value;
}

local success, errorMessage = pcall(dataStore.SetAsync, dataStore, player.UserId, tableToSave)

if success then
    print("Data has been saved!")
else
    print("Data has not been saved!")
end

end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Wait()
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local clicks = Instance.new("IntValue")
clicks.Name = "Clicks"
clicks.Parent = leaderstats
clicks.Value = 321

local rebirths = Instance.new("IntValue")
rebirths.Name = "Rebirths"
rebirths.Parent = leaderstats
rebirths.Value = 123

local data = nil

local success, errorMessage = pcall(function() 
    data = dataStore:GetAsync(player.UserId)
end)

if success and data then
    clicks.Value = data[1]
    rebirths.Value = data[2]
else
    print("The Player has no Data!")
    warn(errorMessage)
end

end)

game.Players.PlayerRemoving:Connect(function(player)
saveData(player)
end)

game:BindToClose(function()
for _, player in ipairs(game.Players:GetPlayers()) do
task.spawn(saveData, player)
end
end)

#

how to fix it

wind crater
#

Looks fine. 😉 No explain what going on, so its looking fine.

worthy orbit
#

but it's not working when i rejoin the game