Profile service or data stores causes unloading a playtest to lag

Everytime I load into a playtest and exit it roblox studio becomes unresponsive for a minute with nothing loaded then loads everything back and becomes responsive. it is not a hardware issue ive tried it on multiple networks and computers. When I disable my data storing script it unloads the playtest fine.

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Template = require(ReplicatedStorage.PlayerData.Template)
local Manager = require(ServerScriptService.PlayerData.Manager)
local ProfileService = require(ServerScriptService.Libs.ProfileService)
local FormatSimple = require(ReplicatedStorage.Libs.FormatNumber.Simple)
local Cache = require(ReplicatedStorage.Libs.Cache)

local ProfileStore = ProfileService.GetProfileStore("Test", Template)
--Main one is Main
local KICK_MESSAGE = "Data issue, try again shortly. If issue persists it could be on our end stay tuned on our discord."

local function LoadProfile(player)
	local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId, "ForceLoad")
	if not profile then
		player:Kick(KICK_MESSAGE)
		return
	end

	profile:AddUserId(player.UserId)
	profile:Reconcile()
	profile:ListenToRelease(function()
		Manager.Profiles[player] = nil
		player:Kick(KICK_MESSAGE)
	end)
	if player:IsDescendantOf(Players) then
		Manager.Profiles[player] = profile

		local playerCache = Cache.new(player)
		playerCache:Load(profile)
		Cache[player] = playerCache
	else
		profile:Release()
	end
end

Players.PlayerAdded:Connect(LoadProfile)

Players.PlayerRemoving:Connect(function(player)
	local profile = Manager.Profiles[player]
	local playerCache = Cache[player]
	if playerCache then
	playerCache:Destroy()
		Cache[player] = nil
	end


	if profile then
		profile:Release()
	end
end)

Hello, You should try Profile Store instand of the Profile Service Module, it was made by the same creator, lorelis, and its much more efficient and very ez to use it, barelly changes the keywords and has its own Docs to help you change it : )

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