I was using Profile Service to manage my game’s data store but for some reason I can’t acces the player profile, at the start of the StatsInit function I define Profiles[player] as profile but if I try to return or print Profiles[player] I just receive nil, even though if I print(Profiles) I can see the “player” key, I also tried to use the user id as a key instead of player but I have the same result.
local Profiles = {}
function DataModule.statsInit(player:Player)
local Profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
if Profile ~= nil then
Profile:AddUserId(player.UserId)
print(Profile.Data)
Profile:Reconcile()
Profile:ListenToRelease(function()
Profiles[player] = nil
player:Kick()
end)
if player:IsDescendantOf(game:GetService("Players")) then
Profiles[player] = Profile
print("Loaded")
print(Profiles)
print(Profile.Data)
print(Profile.Data.PStats)
print(Profiles[player])
StatsModule.Init(player,Profile.Data)
print(1)
DataModule.Share(player)
print(2)
DataModule.addToInventory(player,1)
print(Profile.Data)
end
else
player:Kick("Error while retrieving data")
end
end
local function getProfile(player)
print(Profiles)
print(player)
print(Profiles[player])
assert(Profiles[player], "Data doesnt exist")
return Profiles[player]
end
(The only time the getprofile() function is called is when I use the addToInventory function so the player’s profile is already inside the profiles table.
When I run the script it will give an error at this line and print “data doesnt exist”, also print(Profiles[player]) only prints nil, so even though Profiles[player] exists I can’t acces it.
`23:08:56.847 Player is instance ? true - Studio
23:08:56.847 Player is: Player - Studio
23:08:56.848 ▶ {...} - Studio
23:08:56.858 ▶ {...} - Studio
23:08:56.867 ▶ {...} - Studio
23:08:56.868 Player is instance ? false - Studio
23:08:56.868 ServerScriptService.DataModule:46: attempt to concatenate string with nil`
so it seems that the function is runnning two times, the first time it has the player as parameter but the second time player is nil.
Okay so I found the error, I was calling the function getprofile using a function called get but to call “get” I used a colon instead of a dot so the first argument that the function getprofile was receiving wasnt player.