Profile Service problems

So I’ve been reconfiguring all of my scripts from Data Stores to Profile Service and it might be because of the load times but for some reason when doing my above-head nametags it doesn’t recognize the player data or leaderstats if I were to swap them.


That occurs when the character is loaded before the profile exists, thereforce causing a nil error as the profile doesn’t exist when it tries to access the profile’s data.

The ideal fix would be making the code yield until the profile exists, if the player has left then halt but if the player exists alongside the profile then continue with the process.

i recommend using ProfileStore instead of ProfileService (ProfileStore is a better version of ProfileService by the same creator) as it’s faster and similar.

There is no point in loading the profile after the character gets added, you can do it after the player is added. Also I see that your manager module isn’t a function, if you turn it into a function it will automatically wait until it loads / returns. I suggest checking out tutorials like the one below:

The tags you are adding would be better off in player instead of the character itself. You can remove them whenever the character is removed.

I’ve been switching over some scripts to how the video has it organized but now one issue I’m running into is my dev products returning errors for some reason. I have my products set up like this

and whenever I try purchasing in game it returns this

It runs the previous line of adding SizeValue to the ball but errors on the Update function which is this

Can you please provide the dev product script.

local marketService = game:GetService("MarketplaceService")
local players = game.Players
local SSS = game:GetService("ServerScriptService")
local ball = game.Workspace:FindFirstChild("ball")
local datastoreService = game:GetService("DataStoreService")

local PlayerData = require(SSS.PlayerData.PlayerDataHandler)
local Manager = require(SSS.PlayerData.Manager)

local purchaseHistory = datastoreService:GetDataStore("PurchaseHistory")

local productFunctions = {}

--[[Size Decrease Products]]--

local TextChatService = game:GetService("TextChatService")
local prefix = "[System] "
local colour = "#b3001b"
local systemMsg = game.ReplicatedStorage:FindFirstChild("Remotes"):WaitForChild("systemMessage")

-- minus 5 size
productFunctions[2686321073] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 5
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 5
	end)
	return true
end

-- minus 10 size
productFunctions[2686321213] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 10
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 10
	end)
	return true
end

-- minus 20 size
productFunctions[2687873203] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 20
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 20
	end)
	return true
end

-- minus 100 size
productFunctions[2687873205] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 100
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 100
	end)
	return true
end

-- minus 250 size
productFunctions[2687873202] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 250
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 250
	end)
	return true
end

-- minus 500 size
productFunctions[2687873204] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 500
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 500
	end)
	return true
end

-- minus 1000 size
productFunctions[2687873200] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 1000
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 1000
	end)
	return true
end

-- minus 1500 size
productFunctions[2687873201] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value -= 1500
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 1500
	end)
	
	systemMsg:FireAllClients(`{player.Name} has decreased the size of the ball by 1500!`, prefix, colour)
	return true
end

-- minus 2500 size
productFunctions[2687873199] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end
	
	ball["The Ball"].SizeValue.Value -= 2500
	PlayerData.Update(player, "Decreased", function(currentValue)
		return currentValue + 2500
	end)
	
	systemMsg:FireAllClients(`{player.Name} has decreased the size of the ball by 2500!`, prefix, colour)
	return true
end


--[[Size Increase Products]]--

local colour = "#15cc08"

-- plus 5 size
productFunctions[2687896579] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 5
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 5
	end)
	return true
end

-- plus 10 size
productFunctions[2687896577] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 10
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 10
	end)
	return true
end

-- plus 20 size
productFunctions[2687896573] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 20
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 20
	end)
	return true
end

-- plus 100 size
productFunctions[2687896578] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 100
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 100
	end)
	return true
end

-- plus 250 size
productFunctions[2687896572] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 250
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 250
	end)
	return true
end

-- plus 500 size
productFunctions[2687896575] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 500
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 500
	end)
	return true
end

-- plus 1000 size
productFunctions[2687896574] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 1000
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 1000
	end)
	return true
end

-- plus 1500 size
productFunctions[2687896576] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end

	ball["The Ball"].SizeValue.Value += 1500
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 1500
	end)
	
	systemMsg:FireAllClients(`{player.Name} has increased the size of the ball by 1500!`, prefix, colour)
	return true
end

-- plus 2500 size
productFunctions[2687896570] = function(receipt, player)
	local profile = Manager.Profiles[player]
	if not profile then return end
	
	ball["The Ball"].SizeValue.Value += 2500
	PlayerData.Update(player, "Increased", function(currentValue)
		return currentValue + 2500
	end)
	
	systemMsg:FireAllClients(`{player.Name} has increased the size of the ball by 2500!`, prefix, colour)
	return true
end


-- functions
local function processReceipt(receiptInfo)
	local userID = receiptInfo.PlayerId
	local productID = receiptInfo.ProductId
	local purchased = false
	
	local playerProductKey = userID .. "_" .. receiptInfo.PurchaseId
	
	local success, errorMsg = pcall(function()
		purchased = purchaseHistory:GetAsync(playerProductKey)
	end)
	
	if success and purchased then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	elseif not success then
		error("Purchase has not been successful:" .. errorMsg)
	end
	
	
	local success, isPurchaseRecorded = pcall(function()
		return purchaseHistory:UpdateAsync(playerProductKey, function(alreadyPurchased)
			if alreadyPurchased then
				return true
			end
			
			local player = players:GetPlayerByUserId(userID)
			if player then
				local handler = productFunctions[productID]

				local success, result = pcall(handler, receiptInfo, player)
				if not success or not result then
					error("Purchase had been unsuccessful:" .. receiptInfo.ProductId)
				end
			end
			
			return true
		end)
	end)
	
	
	if not success then
		error("Purchase datastore has been unsuccessful!")
		return Enum.ProductPurchaseDecision.NotProcessedYet
	elseif isPurchaseRecorded == nil then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	else
		return Enum.ProductPurchaseDecision.PurchaseGranted
	end
end

marketService.ProcessReceipt = processReceipt

I know ProfileService has a method for doing dev products but I have no idea how to use it so I’m just trying to figure out how to make it work with this script.