ProfileService:Release() is not apart of the table

No matter how I try to call :Release(), it errors saying its not apart of the table, and data refuses to load.

PlayerAdded function:

function Data.PlayerJoined(player)
	warn("LOADING")
	if Data.Profiles[player.UserId] then
		Data.Profiles[player.UserId]:Release();
		player:Kick("Your data is currently being locked in session: " .. game.JobId .. ", please rejoin.");
		return;
	end
	local profile = DataStore:LoadProfileAsync(tostring(player.UserId), false, "Repeat");
	local self = {};
	
	if profile and player then
		warn("Loading 1/4")
		if player.Parent then
			warn("Loading 2/4")
			profile:AddUserId(player.UserId);
			profile:Reconcile();
			
			profile:ListenToRelease(function()
				player:Kick("Your data is released.");
				Data.Profiles[player.UserId] = nil;
			end)
			
			if Data.Profiles[player.UserId] then
				Data.Profiles[player.UserId]:Release();
				player:Kick("Your data was already loadred in this session. Please rejoin.");
			else
				warn(profile)
				warn("Loading 3/4")
				self = setmetatable(profile, Data);
				Data.Profiles[player.UserId] = self;
				warn("Loaded 4/4");
				return (self);
			end
		end
	end
	return self;
end

PlayerRemoving:

-- Stored in another script ~ shouldn't be a problem.
game.Players.PlayerRemoving:Connect(function(player)
	if rakeData.Profiles[player.UserId] then
		rakeData.Profiles[player.UserId]:Release();
	end
end)

Any ideas?

2 Likes

You set the players user id value to self instead of the profile.

2 Likes

What do you mean? The line that sets data:
Data.Profiles[player.UserId] = self;
That doesn’t set the user id, it sets an index in a table.

2 Likes

You can’t release self since it has no method attached. That must be the profile for it to work.

2 Likes

It is the profile. If I didn’t do the metatable, it prints the same table which is here:

  00:36:45.542   â–Ľ  {
                    ["Data"] =  â–¶ {...},
                    ["GlobalUpdates"] =  â–¶ {...},
                    ["KeyInfo"] = Instance,
                    ["KeyInfoUpdated"] =  â–¶ {...},
                    ["MetaData"] =  â–¶ {...},
                    ["MetaTagsUpdated"] =  â–¶ {...},
                    ["RobloxMetaData"] = {},
                    ["UserIds"] =  â–¶ {...},
                    ["_hop_ready"] = false,
                    ["_hop_ready_listeners"] =  â–¶ {...},
                    ["_is_user_mock"] = false,
                    ["_load_timestamp"] = 89904.4512487,
                    ["_profile_key"] = "4757579613",
                    ["_profile_store"] =  â–¶ {...},
                    ["_release_listeners"] =  â–¶ {...}
                 }  -  Server - RakeData:52

So I don’t see what you mean.

Did you try not setting the metatable? Looking at your code, it does not look like you are using metatables in a correct manner.

1 Like

How am I using it wrong then? Everything works except the :release() function.

You’re setting the metatable for no reason at all. You should be using meta methods if you want to do that.

I find it weird that you are assigning a metatable to the profile with meta methods from data itself?

1 Like

I’m setting it and using it later on for other functions… what do you mean by metamethods? I’ve tried setting ._index and all, and I’ve seen similar implementations work just fine.

That’s not how OOP works. In this situation, it doesn’t look like you are using it as player joined is just a standalone function. As said, try just setting the reference of self to the profile instead.

1 Like

Regardless, that doesn’t answer my request. Yes, that could fix it, but that wouldn’t explain why it’s not working in this case. Your suggestion is also going to require me rewriting a lot of functions because every function to change, or get data, is stored in that metatable.

1 Like

Shouldn’t that be setmetatable(data, {__index = your index}) then?

1 Like

Nope, that broke everything including every profile service function that needs to run.

1 Like

I think the problem here is that you setting all indexes from profile to go to another table which is data. It’s hard to see what the root cause is if I can’t see your meta method logic.

1 Like

Hmm… this isn’t the issue. I’ve seen similar systems use the exact same logic. The only difference is I have a few functions on data. Like these:

function Data:removeItem(name)
	for i, v in pairs(self.Data.Items) do
		if v.Amount <= 0 and v.Name == name then
			table.remove(self.Data.Items, i);
			return;
		end
	end
	return;
end

function Data:AddItem(name, amount)
	local itemData = items[name];
	for i, v in pairs(self.Data.Items) do
		if v.Name == name then
			v.Amount += amount;
			self:removeItem(name);
			return;
		end
	end
	
	table.insert(self.Data.Items, {
		Name = name,
		ID = itemData.ID,
		Amount = amount,
		Locked = false;
	})
	return
end

1 Like

To addon, even when referencing the Direct Profile, I still get this error:

ServerScriptService.Modules.RakeData:64: attempt to call missing method 'Release' of table  -  Server

This time, I didnt have it set metatables.

And the other methods work just fine?

Yes. All methods aside from :Release() work just as intended.

Could you double check if there is a method like that in the ProfileService module? Also print the data table ryt before you call the Release function

Table prints everytime no problem. And profile service does come in a built in :Release(), according to api docs and the module itself.