Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why doesen't the script save data with SetAsync()?

Asked by
Vik954 48
4 years ago

I made a code to save data, and there are no errors, but it doesn't save any data. Why? Here's the code:

 local DataStoreService = game:GetService("DataStoreService")

local WinsDataStore = DataStoreService:GetDataStore("WinsDataStore")

local LeaderboardNameDataStore = DataStoreService:GetDataStore("LeaderboardNameDataStore")

local LeaderboardDataStore = DataStoreService:GetOrderedDataStore("LeaderboardDataStore")

local Players = game.Players

local Leaderstats = game.ServerStorage.leaderstats



local function InsertData(Player)

local Id = Player.UserId

local ChangedId = "Player_" .. tostring(Id)

local Data = WinsDataStore:GetAsync(ChangedId)

if not Data then

WinsDataStore:SetAsync(ChangedId, 0)

LeaderboardDataStore:SetAsync(ChangedId, 0)

LeaderboardNameDataStore:SetAsync(ChangedId, Player.Name)

end

local LocalLeaderstats = Leaderstats:Clone()

LocalLeaderstats.Parent = Player

LocalLeaderstats.Wins.Value = WinsDataStore:GetAsync(ChangedId)

end



Players.PlayerAdded:Connect(InsertData)



while wait(0.01) do

local TotalPlayers = Players:GetChildren()

for i = 1, #TotalPlayers do

local ActualPlayer = TotalPlayers[i]

local ActualWins = ActualPlayer:WaitForChild("leaderstats").Wins.Value

WinsDataStore:SetAsync("Player_" .. tostring(ActualPlayer.UserId), ActualWins)

LeaderboardDataStore:SetAsync("Player_" .. tostring(ActualPlayer.UserId), ActualWins)

LeaderboardNameDataStore:SetAsync("Player_" .. tostring(ActualPlayer.UserId), ActualPlayer.Name)

end

end

Answer this question