Issue
I am using the ProfileStore librairy and I am actively trying to require the Setup Script
Setup Script I'm using
local RunService = game:GetService("RunService")
local PlayerDatatemplate = require(game.ReplicatedStorage.Data["Player Data"])
local ProfileStore = require(game.ServerScriptService.Librairies.ProfileStore)
local DataStoreKey = "Testing1"
local PlayerStore = ProfileStore.New(DataStoreKey, PlayerDatatemplate.PlayerDefaultData)
local Profiles: {[Player]: typeof(PlayerStore:StartSessionAsync())} = {}
local Local = {}
local Shared = {}
function Local.OnStart()
for _, Player in game.Players:GetPlayers() do
task.spawn(Local.LoadProfile, Player)
end
game.Players.PlayerAdded:Connect(Local.LoadProfile)
game.Players.PlayerRemoving:Connect(Local.RemoveProfile)
end
function Local.LoadProfile(Player: Player)
local Profile = PlayerStore:StartSessionAsync(`{Player.UserId}`, {
Cancel = function()
return Player.Parent ~= game.Players
end,
})
if Profile == nil then
return Player:Kick("Data not loaded")
end
Profile:AddUserId(Player.UserId)
Profile:Reconcile()
Profile.OnSessionEnd:Connect(function()
Profiles[Player] = nil
Player:Kick()
end)
local isInGame = Player.Parent == game.Players
if isInGame then
Profiles[Player] = Profile
print(Profiles[Player])
else
Profile:EndSession()
end
end
function Local.RemoveProfile(Player: Player)
local Profile = Profiles[Player]
if Profile ~= nil then
Profile:EndSession()
end
end
function Shared.GetData(Player: Player): PlayerDatatemplate.PlayerData
local Profile = Profiles[Player]
if not Profile then return end
return Profile.Data
end
Local.OnStart()
return Shared
The issue is though that the script which is trying to require it, performs on it without fully being fully loaded and ready to provide the player’s data, returning an empty table.
Is there a possible way for the script to wait itself till the PlayerData is loaded and ready?