I want to reference profile service from a module
Here is the Profile cache module
local Players = game:GetService("Players")
local cachedProfiles = {}
local ProfileService = self.Modules.ProfileService
local CashRates = 10
local saveStructure = {
Wins = 0;
Coins = 0;
Inventory = {"Default"}
}
local PlayerProfileStore = ProfileService.GetProfileStore("PlayerSaveData", saveStructure)
local function PlayerDataLoaded(player)
local profile = cachedProfiles[player]
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local Wins = Instance.new("IntValue")
Wins.Name = "Wins"
Wins.Value = profile.Data.Wins
Wins.Parent = folder
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Value = profile.Data.Coins
Coins.Parent = folder
spawn(function()
while true do
local profile = cachedProfiles[player]
if profile ~= nil then
Wins.Value = profile.Data.Wins
Coins.Value = profile.Data.Coins
else
break
end
wait(0.1)
end
end)
spawn(function()
while true do
local profile = cachedProfiles[player]
if profile ~= nil then
profile.Data.Coins = profile.Data.Coins + CashRates
else
break
end
wait(5)
end
end)
print(player.Name .. "'s data is loaded")
end
local function PlayerAdded(player)
local profile = PlayerProfileStore:LoadProfileAsync("Player_" .. player.UserId, "ForceLoad")
if profile ~= nil then
profile:ListenToRelease(function()
cachedProfiles[player] = nil
player:Kick("Your profile has been loaded remotely. Please rejoin.")
end)
if player:IsDescendantOf(Players) then
cachedProfiles[player] = profile
PlayerDataLoaded(player)
else
profile:Release()
end
else
player:Kick("Unable to load saved data. Please rejoin.")
end
end
for _, player in ipairs(Players:GetPlayers()) do
spawn(function()
PlayerAdded(player)
end)
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(function(player)
local profile = cachedProfiles[player]
if profile ~= nil then
profile:Release()
end
end)
return cachedProfiles
I required the profile service module and It seems I’m referencing the module wrong. How do I reference it right here is my explorer I require the module is DataService: