Whenever I try to save my data, it’s not saving. I’ve used DatastoreEditor to edit my data, and it’s saying that I don’t have it. It’s just not loading and I don’t know what’s wrong.
--# DataHandler.Lua will make sure we can load data of owner boomboxes, and our music value.
local V1PER = require(game.ReplicatedStorage.V1PER)
local OwnedBoomboxes = game:GetService("DataStoreService"):GetDataStore("OwnedBoomboxes")
game.Players.PlayerAdded:Connect(function(Player)
local Data = V1PER.DataStoreResource.Builder.BuildNewLeaderstats({
{
Name = "Music",
TypeValue = "Int",
Default = 0
}
}, Player)
V1PER.DataStoreResource.DataStore.LoadData(Player, Data)
local retrievedData
local found, errorOccured = pcall(function()
retrievedData = OwnedBoomboxes:GetAsync(Player.UserId.. "$")
end)
if found then
if retrievedData then
warn("Player has existing data")
if type(retrievedData) == "table" then
warn("List of owned boomboxes: true")
local BoomboxesOwned = script:WaitForChild("BoomboxesOwned"):Clone()
BoomboxesOwned.Parent = Player
for name, owned in pairs(retrievedData) do
if require(BoomboxesOwned)[name] then
require(BoomboxesOwned)[name] = owned
game.ReplicatedStorage.Boomboxes:WaitForChild(name):Clone().Parent = Player.Backpack
end
end
else
error("Cannot be an instance type that is not a table!")
end
else
warn("Player has no data!")
local BoomboxesOwned = script:WaitForChild("BoomboxesOwned"):Clone()
BoomboxesOwned.Parent = Player
end
else
error(errorOccured)
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
V1PER.DataStoreResource.DataStore.SaveData(Player)
local list = require(Player:WaitForChild("BoomboxesOwned"))
local success, err = pcall(function()
OwnedBoomboxes:SetAsync(Player.UserId.. "$", list)
end)
if success then
for boombox, owned in pairs(list) do
warn("Name; ".. tostring(boombox))
warn("Owned; ".. tostring(owned))
end
warn("Saved player boomboxes")
else
error(err)
end
end)