It’s a strange warning that appears in the output even though i already set Gold as a NumberValue and defined some values in sessionData[player.UserId]
btw the error appears near the bottom of the script
-- Loads player's stats
local function PlayerAdded(player)
-- Creates leaderboard and its stats
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local money = Instance.new("NumberValue")
money.Name = "Gold"
money.Parent = leaderstats
local success = nil
local playerData = nil
local attempt = 1
repeat
success, playerData = pcall(function()
return database:GetAsync(player.UserId) -- Attempting to retrieve player sessionData from Roblox Datastores
end)
attempt += 1
if not success then
warn(playerData)
task.wait(3)
end
until success or attempt == 5
if success then
print("Data retrieved")
if not playerData then
print("New player, giving default playerData")
playerData = {
["Gold"] = 20,
["Other"] = 2
}
end
sessionData[player.UserId] = playerData
for i, v in playerData do
print(v, playerData, playerData.Gold)
end
else
warn("Unable to get sessionData for player ", player.UserId)
player:Kick("There was a problem when getting your sessionData, try rejoin the game")
end
money.Value = sessionData[player.UserId].Gold -- Line where error appears
money.Changed:Connect(function()
sessionData[player.UserId].Gold = player.leaderstats.Gold.Value
end)
leaderstats.Parent = player
end
Players.PlayerAdded:Connect(PlayerAdded)
Can someone please help with this problem
Thank you!