So i want to save a value of numbervalue that is inside every tool in my backpack, im using table for this, but for some reason this don’t save them. (I checked if table is saved using Datastore editor plugin)
game.Players.PlayerRemoving:connect(function(player)
player.Character.Humamoid:UnequipTools()
local valuesToSave = {}
for _, v in pairs(player.Backpack:GetChildren()) do
valuesToSave[v.Name] = v:WaitForChild("Amount").Value
end
MyDataStore:SetAsync(player.UserId, valuesToSave)
end)
game.Players.PlayerRemoving:connect(function(player)
player.Character.Humamoid:UnequipTools()
local valuesToSave = {}
for _, v in pairs(player.Backpack:GetChildren()) do
valuesToSave[v.Name] = v:WaitForChild("Amount").Value
MyDataStore:SetAsync(player.UserId,v.name)
end
end)
ist it will just save a name of last instance? as it will save not table but name and it will rewrite it for every tool so it will save only last tool name.
The reason why you are getting this error is because you spelt Humanoid wrong. Here is your code with the correct spelling:
game.Players.PlayerRemoving:Connect(function(player)
player.Character.Humanoid:UnequipTools()
local valuesToSave = {}
for _, v in pairs(player.Backpack:GetChildren()) do
valuesToSave[v.Name] = v:WaitForChild("Amount").Value
end
MyDataStore:SetAsync(player.UserId, valuesToSave)
end)
Instead of using SetAsync() you should look into using UpdateAsync() because
“SetAsync() can be hazardous since it overwrites any value currently in the entry. If you’re updating an existing entry, UpdateAsync() is recommended because it considers the old value before making changes.” - Quoted from the developers hub