Hi,
I am having problems trying to store button position values… How do I go around storing a dictionary in a data store?
local DataManager = {}
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ProfileService = require(script.ProfileService)
local DataTable = {
ButtonPositions = {
[1] = UDim2.new(0,0,0),
[2] = UDim2.new(0,0,0),
[3] = UDim2.new(0,0,0),
[4] = UDim2.new(0,0,0)
};
}
local ProfileStore = ProfileService.GetProfileStore("Test1", DataTable)
local Profiles = {}
local function HandleLockedUpdate(GlobalUpdates, Update)
local id = Update[1]
local data = Update[2]
GlobalUpdates:ClearLockedUpdate(id)
end
local function OnPlayerAdded(player)
local profile = ProfileStore:LoadProfileAsync(
"Player_"..player.UserId,
"ForceLoad"
)
if profile then
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(Players) then
Profiles[player] = profile
local globalUpdates = profile.GlobalUpdates
for index, update in pairs(globalUpdates:GetActiveUpdates())do
globalUpdates:LockActiveUpdate(update[1])
end
for index, update in pairs(globalUpdates:GetLockedUpdates())do
HandleLockedUpdate(globalUpdates, update)
end
globalUpdates:ListenToNewActiveUpdate(function(id, data)
globalUpdates:LockActiveUpdate(id)
end)
globalUpdates:ListenToNewLockedUpdate(function(id, data)
HandleLockedUpdate(globalUpdates, {id, data})
end)
else
profile:Release()
end
else
player:Kick("Data loading failed")
end
end
local function OnPlayerRemoving(player)
local profile = Profiles[player]
if profile then
profile:Save()
profile:Release()
end
end
-- Public Methods
function DataManager:GetData(player)
local profile = Profiles[player]
if profile then
return profile.Data
else
return nil
end
end
function DataManager:GetProfileStore()
return ProfileStore
end
function DataManager:UpdateData(player, key, data)
local profile = Profiles[player]
if key == "" then
if profile.Data[key] and profile.Data[key] > data then
return
end
end
profile.Data[key] = data
print("UpdateData:" ,player, key, data)
end
function DataManager:SaveData(player)
Profiles[player]:Save()
end
function DataManager:ClearData(player)
if RunService:IsStudio() and RunService:IsServer() then
local profile = Profiles[player] or ProfileStore:LoadProfileAsync(
"Player_"..player.UserId,
"ForceLoad"
)
profile["Data"] = DataTable
player:Kick("Data Cleared")
end
end
Players.PlayerAdded:Connect(OnPlayerAdded)
Players.PlayerRemoving:Connect(OnPlayerRemoving)
return DataManager