I want to know an efficient way of loading players data, then giving the stats the data the player has. I also want to know an efficient way of giving a player their tools on respawn.
So an efficient way of loading player’s data is shown in the part of code below. How I’d give player their data is create a table of players in the server and then another table inside for each player which would contain their data.
function module:load(key)
local success, data = pcall(dataStore.GetAsync, dataStore, key)
if (success and data) then
--give player their data
elseif (success and not data) then
--create a new data
else
delay(30, function() module:load(key) end) --if no success, function calls itself after 30 seconds
end
end
In order to give player their tools once they respawn is storing them in StarterGear which is located in the player itself.
What about the part where you give the player their stats? Like add the data to values.
Also wouldn’t that be laggy if a player leaves the game when there is no success, or data? It would keep repeating itself.
Yeah you could give it n amount of available tries. However, this is how I give players their data
function module:load(key)
local success, data = pcall(dataStore.GetAsync, dataStore, key)
if (success and data) then
playersTab[player.UserId] = data
elseif (success and not data) then
playersTab[player.UserId] = {
Points = 0;
}
else
delay(30, function() module:load(key) end) --if no success, function calls itself after 30 seconds
end
end