MY ISSUE: Everyone data is the same after random generating a value.
→ random generator works FINE
→ data loads but everyone has the SAME data after being random generated
Here’s the code:
function DataHandler:RandomItemFromTbl(tbl)
local RNG = Random.new();
local counter = 0;
for i,v in pairs(tbl) do
counter += tbl[i][2]
end
local chosen = RNG:NextNumber(0, counter)
for i,v in pairs(tbl) do
counter -= tbl[i][2]
if chosen > counter then
return tbl[i][1]
end
end
end
function DataHandler:characterSetUp(player)
if DataManager.Profiles[player].Data.IsFirstLoad ~= true then
DataManager.Profiles[player].Data.IsFirstLoad = true
if DataManager.Profiles[player].Data.Race == "None" then
local newRace = DataHandler:RandomItemFromTbl(Info.Races)
DataManager.Profiles[player].Data.Race = newRace
end
end
end
local function playerAdded(player)
local profileData = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if profileData ~= nil then
profileData:AddUserId(player.UserId)
profileData:Reconcile()
profileData:ListenToRelease(function()
DataManager.Profiles[player] = nil
player:Kick("Data error at releasing")
end)
if player:IsDescendantOf(game.Players) then
DataManager.Profiles[player] = profileData
DataHandler:characterSetUp(player)
print(DataManager.Profiles[player].Data)
else
profileData:Release()
end
else
player:Kick("Data error")
end
end
function DataHandler:Init()
for _, player in pairs(game.Players:GetPlayers()) do
task.spawn(playerAdded,player)
end
game.Players.PlayerAdded:Connect(playerAdded)
game.Players.PlayerRemoving:Connect(function(player)
if DataManager.Profiles[player] ~= nil then
DataManager.Profiles[player]:Release()
end
end)
end
Anything will help