New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Still have questions? Join our Discord server and get real time help.
Log in to vote

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

Asked by
Vik954 48
1 year 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)


local LocalLeaderstats = Leaderstats:Clone()

LocalLeaderstats.Parent = Player

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



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)



Answer this question