How to load a profile using Profile Service from main place to a sub place?

I have a slot system for my game using profile service which I followed from a YouTube tutorial but the slots are only loaded in the main game. I have researched plenty of topics like this but they are all using datastore. I understand they can do this with GetAsync() but when I attempted to do the same using LoadProfileAsync() and test it I would get this error

Profile does not exist of 4285955275  -  Server - Script:19

Here is my data handler module script which is inside of the place that I want the slot to be loaded

local PlayerDataHandler = {}

local ProfileService = require(game.ServerScriptService.ProfileService)
local Players = game:GetService("Players")

local dataTemplate = {
	Cash = 0,
	Exp = 0,
	Inventory = {}
}

local ProfileStore = ProfileService.GetProfileStore(
	"PlayerProfile",
	dataTemplate
)
game.Players.PlayerAdded:Connect(function(plr)
	print(plr, " added")
	local success, errorMessage = pcall(function() -- pcalls catch errors
		print("loading data")
		ProfileStore:LoadProfileAsync(plr:GetAttribute("Slot")..plr.UserId)
	end)
end)

return PlayerDataHandler

Any help would be appreciated

2 Likes

bump :upside_down_face:
30char30char30char30char

Bump :smiling_face_with_tear:
Please help
30char30char

Bumping after an hour isn’t neccessary…


I believe that the issue may be related to plr:GetAttribute("Slot"), namely that it could be returning a blank string. I assume that when you are saving it, the value of plr:GetAttribute("Slot") would be a non-blank string.

You’ll have to ensure that the attribute Slot is set prior to trying to load it.

Hi thanks for your response, your answer makes sense now that i think about it. Im new to profile service so I apologize in advance for anything stupid that I say. My first idea would be to use messaging service to send the attribute but that sounds really stupid to me. Could you give me some ideas?

You mentioned you are using subplaces, so you would probably be using TeleportService, right?
I believe that when you teleport a player, you can pass some information along with them, which you can then read from the subplace. If you send along the slot value, then you can easily access it.

1 Like

Hey I was busy yesterday so I’m sorry for the late reply but Im not sure how to get the TeleportData from :GetJoinData.

player:GetJoinData().TeleportData. It looks like you are using a table within the teleport data, so this should work:

local slot = player:GetJoinData().TeleportData[1]
1 Like

Seems like the key is loading but I still get the same error message. Im beginning to think its not possible to load data in a sub place with profile service :confused:


here the updated portion o fmy code

local Players = game:GetService("Players")
local TeleportService = game:GetService("TeleportService")

local teleportOptions = Instance.new("TeleportOptions")

local playerToTeleport = Players:GetPlayers()[1] -- get the first user in the experience

local ProfileService = require(game.ServerScriptService.ProfileService)
local Players = game:GetService("Players")

local ProfileStore = ProfileService.GetProfileStore(
	"PlayerProfile",
	dataTemplate
)

local Profiles = {}



local function playerAdded(plr)

	local joinData = plr:GetJoinData()
	if joinData then
		local slot = joinData.TeleportData[1]
		plr:SetAttribute("Slot", slot)
	end
	
	
	repeat wait() until plr:GetAttribute("Slot") ~= nil or plr:GetAttribute("Slot")

	print("loaded with slot key", plr:GetAttribute("Slot"))

	local profile = ProfileStore:LoadProfileAsync(plr:GetAttribute("Slot")..plr.UserId)

	if profile then
		profile:AddUserId(plr.UserId)
		profile:Reconcile()

		profile:ListenToRelease(function()
			Profiles[plr] = nil

			plr:Kick()
		end)

		if not plr:IsDescendantOf(Players) then
			profile:Release()
		else
			Profiles[plr] = profile

			print(Profiles[plr].Data)
		end
	else
		plr:Kick()
	end

end

I think i got it to work since im not getting that error message now, I just had to simply use if statements

if joinData then
		local slot = joinData.TeleportData[1]
		if slot == "Slot_1" then
			plr:SetAttribute("Slot", "Slot_2")
		end
		if slot == "Slot_2" then
			plr:SetAttribute("Slot", "Slot_2")
		end
	end

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