I heard that it takes a wait time of 6 seconds to SetAsync a players data. But I am trying to set ALL of the player's data before as the player is removed. But I am stuck on what to do here..
Module script:
return {
PlayerData = { Coins = 0, Diamonds = 0, Experience = 0, Kills = 0, Level = 0, EXPneeded = 0, }
}
script:
local DataStore = game:GetService("DataStoreService"):GetOrderedDataStore("PlayerDataV1");
local DataModule = require(game.ReplicatedStorage.PlayerData)
game.Players.PlayerAdded:Connect(function(plr)
for i, v in pairs(DataModule.PlayerData) do
DataModule.PlayerData[i] = DataStore:GetAsync(plr.UserId, i) -- this is good.
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
for i, v in pairs(DataModule.PlayerData) do
DataModule.PlayerData['Coins'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Coins']) --[[
DataModule.PlayerData['Diamonds'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Diamonds'])
DataModule.PlayerData['Experience'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Experience'])
DataModule.PlayerData['Kills'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Kills'])
DataModule.PlayerData['Level'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['Level'])
DataModule.PlayerData['EXPneeded'] = DataStore:SetAsync(plr.UserId, DataModule.PlayerData['EXPneeded'])
]]-- I want to add the rest of these without throttle.
end
end)

7 comments
It is, my module script have playerdata = {info is in here.} I should post the Module script too.
Oh. Then why aren't you calling it like that? If you're making calls to tables the other way around then it doesn't seem like you're doing it that way. Can you post the ModuleScript?
Yes, I posted it.
Yeah, just set the entire thing as the current PlayerData and then get each value out of the table. You don't have to post one singular number to SetAsync, you can post an entire table if you need to.
I want to save not one instance, but all, at the same time, I want to prevent it from throttling as the player leaves the game.
Right. Currently you're unpacking each individual value and pushing them individually, and what you might want to do is instead push the entire PlayerData table. There won't be any throttling if a bunch of players leave at once, either.
It works, but my studio still crashes everytime I leave it.