Hi there,
I started making a data management module for a framework, and I have ran into a problem. Basically, on the player data load function, I have a bindable that is supposed to fire when the data is fully loaded, but it doesn’t.
Here is the function in question:
--[[
DataStoreObject:LoadDataAsync(player: Player, reconcileData: boolean?): PlayerDataObject
Loads the player data and allows you to change it.
[player]: The player the data should be loaded for.
[reconcileData (Optional)]: Will automatically make any loaded profile reconcile its data.
--]]
function DataStoreObject:LoadDataAsync(player: Player, reconcileData: boolean?)
reconcileData = reconcileData or true
local PlayerDataObject = setmetatable({ }, DataStoreObjectHidden)
local PlayerProfile = self.DataStore:LoadProfileAsync(string.format(Settings.KeyStringPattern, player.UserId))
PlayerDataObject.KeyChanged = Signal.new() :: ScriptSignal
PlayerDataObject.KeyRemoved = Signal.new() :: ScriptSignal
PlayerDataObject.DataLoaded = Signal.new() :: ScriptSignal -- Signal that doesn't work.
PlayerDataObject.LoadedPlayers = { } :: LoadedPlayers
PlayerDataObject.Player = player
if PlayerProfile then
PlayerProfile:AddUserId(player.UserId)
if reconcileData then
PlayerProfile:Reconcile()
end
PlayerProfile:ListenToRelease(function()
PlayerDataObject.LoadedPlayers[player] = nil
player:Kick("Code 1:\n\n Player data was loaded on another server.")
end)
if player:IsDescendantOf(Players) then
PlayerDataObject.LoadedPlayers[player] = PlayerProfile
PlayerDataObject.DataLoaded:Fire() -- Where it fires
else
PlayerProfile:Release()
end
else
player:Kick("Code 2:\n\n Player data was trying to be loaded on another server at the same time.")
end
return PlayerDataObject
end
Everything works, even past the point it fires, but it just doesn’t fire for whatever reason.
Here is the script where I load the data:
local DataService = require(script.Parent.DataService)
local Players = game:GetService("Players")
local QC = require(script.QuickAccess)
local MyDataStore = DataService.CreateDataStore("PlayerData", {LogInTimes = 0})
Players.PlayerAdded:Connect(function(Player)
local PlayerData = MyDataStore:LoadDataAsync(Player)
-- tried printing player data here and such, it worked so obviously it loads.
PlayerData.DataLoaded:Connect(function()
local LogInTimesKey = PlayerData:GetKey("LogInTimes")
print(Player.Name, LogInTimesKey)
PlayerData:SetKey("LogInTimes", LogInTimesKey + 1)
PlayerData.KeyChanged:Connect(function(key, value)
if key == "LogInTimes" then
LogInTimesKey = value
end
end)
---
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local LogInTimes = Instance.new("NumberValue")
LogInTimes.Name = "Log-in Times"
LogInTimes.Value = LogInTimesKey
LogInTimes.Parent = Player
end)
end)
Players.PlayerRemoving:Connect(function(Player)
MyDataStore:ReleaseSessionLock(Player)
end)
MyDataStore.SessionLockReleased:Connect(function(player: Player)
print(string.format("Released session lock for %s.", player.Name))
end)
Hope you can help, and thanks!