Well, I am trying to save the tools (apparently if they are saved) and load the tools, apparently I get an error when trying to get the names of the tools and I do not know the problem
local function GetTools(player, profile)
if profile.Data.Tools ~= nil then
for _, Tools in pairs(profile.Data.Tools) do--Here I get the error, an "pairs"
if not toolsFolder:FindFirstChild(Tools) then continue end
local Tool = toolsFolder[Tools]:Clone()
Tool.Parent = player:WaitForChild("Backpack")
local ToolGear = toolsFolder[Tools]:Clone()
ToolGear.Parent = player:WaitForChild("StarterGear")
end
end
end
Players.PlayerAdded:Connect(function(player)
local Profile = DataManager:Get(player, true)
if not Profile then
repeat task.wait(0.1)
Profile = DataManager:Get(player, true)
until Profile or (not player.Parent)
end
if Profile then
GetTools(player, Profile)
player:WaitForChild("Backpack").ChildAdded:Connect(function()
for _, GetTools in pairs(player:WaitForChild("Backpack"):GetChildren()) do
table.insert(Profile.Data.Tools, GetTools.Name)
end
end)
end
end)
These are the ProfileService data:
local Players = game:GetService("Players")
local ProfileService = require(script.ProfileService)
local saveStructure = {
Tools = {};
Money = 0;
LogInTimes = 0;
LogInGiift = 0;
}
Can you show us the code where you update Profile.Data.Tools? My best guess is you’re overriding it with the actual tool name instead of indexing/inserting the tool name into the array.
or do you mean the whole script that gets the data from the ProfileService?
Here is all about the ProfileService data
local Players = game:GetService("Players")
local ProfileService = require(script.ProfileService)
local saveStructure = {
Tools = {};
Money = 0;
LogInTimes = 0;
LogInGiift = 0;
Shadows = "Medio";
Water = "Medio";
Tree = "Enabled";
FPS = "UnEnabled";
Ping = "UnEnabledPing";
BrilloVol = 0.7;
PlayerChose = "ForLocalPlayer";
Language = "English";
SlotsInventory = 90;
Crouch = "Keep";
Sprint = "Keep";
}
local PlayerProfileStore = ProfileService.GetProfileStore("test14", saveStructure)
local cachedProfiles = {}
local function DoSomethingWithALoadedProfile(player, profile)
local GiftMoney = math.random(100, 270)
profile.Data.LogInTimes = profile.Data.LogInTimes + 1
profile.Data.LogInGiift = profile.Data.LogInGiift + 1
print(player.Name, " has logged in " .. tostring(profile.Data.LogInTimes).. " time" .. ((profile.Data.LogInTimes > 1) and "s" or ""))
if profile.Data.LogInGiift >= 120 then
profile.Data.Money = profile.Data.Money + GiftMoney
print(player.Name, "has been given a gift of $".. GiftMoney.. ".", "Actualmente tiene $".. profile.Data.Money.. ".")
profile.Data.LogInGiift = 0
else
print(player.Name .. " owns " .. tostring(profile.Data.Money) .. " now!")
end
end
local function PlayerAdded(player)
local profile = PlayerProfileStore:LoadProfileAsync("Player_".. player.UserId, "ForceLoad")
if profile ~= nil then
profile:Reconcile()
profile:ListenToRelease(function()
cachedProfiles[player] = nil
player:Kick("Tus datos no han sido cargados. Por favor Ăşnase nuevamente")
end)
if player:IsDescendantOf(Players) then
cachedProfiles[player] = profile
DoSomethingWithALoadedProfile(player, profile)
else
profile:Release()
end
else
player:Kick("No se pueden cargar tus datos. Por favor Ăşnase nuevamente")
end
end
for _, player in ipairs(Players:GetPlayers()) do
coroutine.wrap(PlayerAdded)(player)
end
local function PlayerRemoving(player)
local profile = cachedProfiles[player]
if profile ~= nil then
profile:Release()
end
end
Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)
function cachedProfiles:Get(player, yield)
local profile = cachedProfiles[player]
if yield and not profile then
repeat task.wait(0.1)
profile = cachedProfiles[player]
until profile or (not player.Parent)
end
if profile then
return profile
end
end
return cachedProfiles
I mean when the player buys or is given a tool, that code might be updating Profile.Data.Tools to be a string (the tool name) instead of it being an array.
Also, change: for _, GetTools in pairs(player:WaitForChild("Backpack"):GetChildren()) do
To for _, Tool in pairs(player:WaitForChild("Backpack"):GetChildren()) do
I don’t think this is directly causing the error ^ but the loop might think GetTools.Name is referencing the function. You’d have to change GetTools.Name to Tool.Name too.
Actually no, at the time I thought about putting that, but then I thought that I would only put a variable from the tool. So in the end I put table.insert
Why not just use the new DataStoreV2? Didn’t it receive some updates that made it more reliable? I don’t know much about ProfileService that much, but I’ve been able to keep my DataStores perfectly fine, so far I haven’t been reported of any data loss since DataStoreV2. (I’m not talking about the DataStore2 module, I’m talking about roblox’s official DataStoreV2)
From what I have seen, there is no script that contains that. Well, now I have another problem, and it is that I already mentioned it before “if there is only one tool and it is saved, when you enter the game again, you will have more tools of the same”
Because you’re doing table.insert when the player loads their data. ProfileService already has your array of tools saved, so when the player joins and you add that tool name (from their backpack in the loop) to the array, you’re duplicating their items.