Error: attempt to perform arithmetic (sub) on number and nil on ProfileService DataStore

I have posted previously on the same code but different problem. It is still regarding to my attempt to follow on a ProfileService DataStore tutorial on YT. I keep getting this error as stated on the Title of this post. The error said to be on Line 13 of the script of MoneyPart.

I do not have solution to this cause I have no idea why it was not able to read the lastUsedMoneyPartTime from the modulescript of DataManager

DataManager (modulescript in ReplicatedStorage)

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

local ProfileStore = ProfileService.GetProfileStore(
	"Player",
	{
		money = 0;
		lastUsedMoneyPartTime = 0;
	}
)

local Profiles = {}

local function onPlayerAdded(player)
	local profile = ProfileStore:LoadProfileAsync(
		"Player_" .. player.UserId,
		"ForceLoad"
	)
	
	if profile then
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick()
		end)
		
		if player:IsDescendantOf(Players) then
			Profiles[player] = profile
		else
			profile:Release()
		end
	else
		player:Kick()
	end
end

local function onPlayerRemoving(player)
	local profile = Profiles[player]
	if profile then
		profile:Release()
	end
end

Players.PlayerAdded:Connect(onPlayerAdded)
Players.PlayerRemoving:Connect(onPlayerRemoving)

---------------------------------------------------

local DataManager = {}

function DataManager:Get(player)
	local profile = Profiles[player]
	
	if profile then
		return profile.Data	
	end
end

return DataManager

Money Part (Script in ServerScriptService)

local DataManager = require(game.ReplicatedStorage.DataManager)

local part = workspace.Money

local function onTouched(touchedPart)
	local player = game.Players:GetPlayerFromCharacter(touchedPart.Parent)
	
	if player then 
		local data = DataManager:Get(player)
		
		if data then
			local currentTime = os.time()
			local timeSinceLastUsedMoneyPart = currentTime - data.lastUsedMoneyPartTime
			local waitTime = 10*60
			
			if timeSinceLastUsedMoneyPart > waitTime then
				data.lastUsedMoneyParTime = currentTime
				data.money += 500
				
				print(player.Name, "now has money:", data.money)
			else
				print(player.Name, "must wait seconds before use: ", waitTime - timeSinceLastUsedMoneyPart)
			end
		else
			print(player.Name, "does not have data profile loaded")
		end
	end
end

part.Touched:Connect(onTouched)

Thank you in advanced

Essentially what it’s saying is data.lastUsedMoneyPartTime being nil.

You also misspelled lastUsedMoneyPartTime in the data.lastUsedMoneyParTime = currentTime line

I believe there’s some underlying flaw in your ProfileService, in some code you haven’t shared, where a wrong argument is passed or something like that resulting in .lastUsedMoneyPartTime being nil.

Yea saw that, I fixed it already

For this one, I believe there shouldnt be any problem ProfileService cause I got it from this Save your player data with ProfileService! (DataStore Module)

its a table that has no variable, assign a variable to it and get the value by typing

whatever.Data.thisVar.valueyours = "something ..."

But the variable is already been assigned in the DataManager modulescript

You’re probably expecting new template values appearing in old profile saves - use Profile:Reconcile() - you can find it being used in the official example and not in the tutorial videos since they’re older than the reconcile method.

Ah… I see… too be honest I dont know how it works or where to place the code. I was relaying on the video to understand how most of the thing I wrote/copied. I will wait for another tutorial that will cover this Profile:Reconcile(). Since you are the original poster of ProfileService DataStore, you probably know the reason of the error im getting :smiley: Thank you

Go on profile service wiki there should be an example code which utilizes profile: Reconcile