ProfileService: Data not found AND Release() not part of player

local ProfileService = require(game:GetService("ServerScriptService"):FindFirstChild("ModuleScripts"):FindFirstChild("ProfileService"))
local ProfileManagerModule = require(game:GetService("ServerScriptService"):FindFirstChild("ModuleScripts"):FindFirstChild("ProfileManager"))

local DataTemplate = {
	Coins = 0,
	PickaxeLevel = "Default",
}

--Active --> for publishing
local ProfileStore = ProfileService.GetProfileStore("Testing", DataTemplate)

local function CreateLeaderstats(player)
	local profile = ProfileManagerModule.Profiles[player]
	if not profile then return end
	
	local PlayerData = Instance.new("Folder")
	PlayerData.Name = "PlayerData"
	PlayerData.Parent = player
	
	local Coins = Instance.new("IntValue")
	Coins.Name = "Coins"
	print(profile.Data)
	Coins.Value = profile.Data.Coins -- sets the value of leaderstats to the data from the profile
	Coins.Parent = PlayerData
	
	local PickaxeLevel = Instance.new("StringValue")
	PickaxeLevel.Name = "PickaxeLevel"
	PickaxeLevel.Value = profile.Data.PickaxeLevel -- sets the value of leaderstats to the data from the profile
	PickaxeLevel.Parent = PlayerData
	
end

local function onPlayerAdded(player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..player.UserId)
	if profile == nil then
		player:Kick("An error with the player's data has occured. Try joining again shortly")
		return
	end
	
	profile:AddUserId(player.UserId) --To follow regulations
	profile:Reconcile() --creates new variables in players data template (if there are some new added in the DataTemplate)
	
	profile:ListenToRelease(function() --Does the function when Release() is called
		ProfileManagerModule.Profiles[player] = nil --remove the players profile from Profile Manager
		player:Kick("Don't worry! The player's data has been saved. The player had to be kicked out to prevent data corruption")
	end)
	
	if player:IsDescendantOf(game:GetService("Players")) then
		ProfileManagerModule.Profiles[player] = player
		CreateLeaderstats(player)
	else
		profile:Release() --Locks the player's profile if they leave before the profile has loaded
	end
end

--If players are in the game before the playeradded event runs
for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
	task.spawn(onPlayerAdded, player)
end

--Players leave
game:GetService("Players").PlayerRemoving:Connect(function(plr)
	local profile = ProfileManagerModule.Profiles[plr]
	if not profile then return end
	profile:Release()
end)

Data is not a valid member of Player “Players.woitur” → when I try to print(Data)

AND

Release is not a valid member of Player “Players.woitur” → PlayerRemoving event

Thank you

Yes, I did try it in game. Still the same issue
image

very small mistake. I am lucky I found it quickly

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