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