Metatable loses profile-service functions

Are you using ProfileService in accordance with the documentation? I’m looking at the source code right now and I don’t see anything awry.

loleris chose to use task.spawn (smart man) and the only other reason for an internal error on ProfileService’s part is misuse.

2 Likes

Yeah for sure it is my problem. I just don’t know where. I followed the documentation as much as I could.

2 Likes

setmetatable overwrites the existing metatable of data, which is currently a reference to the profile, so it no longer has access to methods in class Profile in ProfileService.

As I understand your aim is to expand data with additional properties and methods. Aside from metatable complications, that exposes some risks in the long run, especially the chance to accidentally overwrite elements that belong to the profile.

I suggest your create a wrapper and treat the profile as a member of the object rather than the object itself.

For instance:

function module.new(player, profile)
    local object = setmetatable({}, module)
    
    object.Profile = profile
    object.Player = player
    -- ...
    
    return object
end

-- And then have methods like:
function module:HasUgc(id)
    return if table.find(self.Profile.Data.GottenUgc, id) then true else false
end


Both scripts also need a review, especially a couple of things, such as:

  • players[plr.Name] and players[plr], which are not the same;
  • as well as clear distinction between self.Data.leaderstats (which would be safer as self.Profile.Data.leaderstats) and the leaderstats folder self.Data.plr.leaderstats (which should not be a part of Profile.Data and rather a separate field in the object).
3 Likes

This did help a lot, now my client is erroring but I’m gonna figure that out, thank you for your help!!!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.