hi.
ProfileService just wont load me the data but somehow still creates stuff in cache.
DataService (Where profileservice is being mainly used in)
local DataService = {}
local RS = game:GetService("ReplicatedStorage")
local SSS = game:GetService("ServerScriptService")
local Players = game:GetService("Players")
local AllItemsTable = require(RS.InfoTables.Items)
local Knit = require(RS.Packages.Knit)
local ProfileTemplate = {
Money = 0,
Items = {},
}
local Cache = require(game.ServerScriptService.Cache)
local ProfileService = require(game.ServerScriptService.ProfileService)
local ProfileStore = ProfileService.GetProfileStore(
"PlayerData",
ProfileTemplate
)
local Profiles = {}
DataService.GiveMoney = function(profile, amount)
if profile.Data.Money == nil then
profile.Data.Money = 0
end
profile.Data.Money = profile.Data.Money + amount
end
DataService.GiveItem = function(profile, item)
print(profile.Data)
if profile.Data.Items == nil then
profile.Data.Items = {}
end
table.insert(profile.Data.Items, item)
Knit.GetController("InventoryController"):AddItem(AllItemsTable[item])
end
DataService.Load = function(player : Player)
local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
print("LOAD")
if profile ~= nil then
print("profile nil")
profile:AddUserId(player.UserId)
profile:Reconcile()
profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick("Data was unable to load. Please rejoin 😅")
end)
if player:IsDescendantOf(Players) == true then
Profiles[player] = profile
print(Profiles)
Cache[player.UserId] = {
data = profile.Data;
}
print("DESCENDANT")
DataService.GiveItem("Basic Egg")
else
profile:Release()
end
else
player:Kick("Data was unable to load. Please rejoin 😅")
end
end
DataService.UnloadAndSave = function(player)
local profile = Profiles[player]
if profile ~= nil then
profile:Release()
end
end
return DataService
PlayerLoad (server script that runs the needed functions to load and save data)
local DataService = require(game:GetService("ServerScriptService").Services.DataService)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
DataService.Load(plr)
end)
Players.PlayerRemoving:Connect(function(plr)
DataService.UnloadAndSave(plr)
end)
Output
59 line is Cache module table
I need help. plz.
P.S. im using a little modifed Knit framework.
