So recently I asked how to get data, because every single time I try to, it fails, now I guess I will show the code. Inside the main Modulo script I have.
local playerStats = {}
ds=game:GetService("DataStoreService")
local playerData = ds:GetDataStore('PlayerData')
function beginPlayerStats(player)
player.WaitForDataReady (player);
if(player.DataReady)then
if(playerData.SetAsync(player.UserId,{power = 0, chakra = 0, health = 0, level = 0, wind = 0, earth = 0, fire = 0, water = 0}) == nil) then
playerData.SetAsync(player.UserId,{power = 0, chakra = 0, health = 0, level = 0, wind = 0, earth = 0, fire = 0, water = 0})
end
end
end
function playerStats.returnPlayerStats(player,stat)
if(player.DataReady) then
if(playerData.SetAsync(player.UserId,{power = 0, chakra = 0, health = 0, level = 0, wind = 0, earth = 0, fire = 0, water = 0 }) ~= nil) then
return playerData.GetAsync(player.UserId,stat)
end
end
end
game.Players.ChildAdded:connect(beginPlayerStats);
return playerStats;
inside my non modulo script I have
b = require(game.ServerScriptService.ModuleScript)
game.Players.ChildAdded:connect(function(player)
player.WaitForDataReady (player );
print(player.DataReady);
print( b.playerStats.returnPlayerStats(player,"level"));
print(player);
end)
And i am getting an error in the modulo script stating SetAsync requires an object in the first param which it should not because it should be a key...

1 comment
That was another problem, but relatively I solved it.