Hello fellow developers -
In all my time as a developer, I’ve never really used DataStores. So I’m learning now.
I want to save 10 Boolean values to the player in a specific folder, each bool being an indicator to a different overhead title that other scripts will reference. I have put this excuse of a script together based of my knowledge and guidance from tutorials and such.
Whenever the game launches, not all of the booleans are even inserted into the folder, and most of the time the pcall fails. I believe it is because of the sheer amount of Data I am trying to save, though like I said before, I’m not sure.
Here is my excuse of a script:
local DataStoreService = game:GetService("DataStoreService")
local dataStore = DataStoreService:GetDataStore("MyDataStore")
local function saveData(player)
local tableToSave = {
player.TitleBools.FAN.Value,
player.TitleBools.DIAMONDMEMBER.Value,
player.TitleBools.ELITEMEMBER.Value,
player.TitleBools.GOLDENMEMBER.Value,
player.TitleBools.HEROICMEMBER.Value,
player.TitleBools.LEGEND.Value,
player.TitleBools.LEGENDARYMEMBER.Value,
player.TitleBools.THEBEST.Value,
player.TitleBools.VALUEDMEMBER.Value,
player.TitleBools.CHAMPION.Value
}
local success, err = pcall(function()
dataStore:SetAsync(player.UserId, tableToSave)
end)
if success then -- If the data has been saved
print("Data has been saved!")
else -- Else if the save failed
print("Data hasn't been saved!")
warn(err)
end
end
game.Players.PlayerAdded:Connect(function(player)
local Folder = Instance.new("Folder")
Folder.Name = "TitleBools"
Folder.Parent = player
local fan = Instance.new("BoolValue")
fan.Name = "FAN"
fan.Parent = Folder
local diamondmember = Instance.new("BoolValue")
diamondmember.Name = "DIAMONDMEMBER"
diamondmember.Parent = Folder
local elitemember = Instance.new("BoolValue")
elitemember.Name = "ELITEMEMBER"
elitemember.Parent = Folder
local goldenmember = Instance.new("BoolValue")
goldenmember.Name = "GOLDENMEMBER"
goldenmember.Parent = Folder
local heroicmember = Instance.new("BoolValue")
heroicmember.Name = "HEROICMEMBER"
heroicmember.Parent = Folder
local legend = Instance.new("BoolValue")
legend.Name = "LEGEND"
legend.Parent = Folder
local legendarymember = Instance.new("BoolValue")
legend.Name = "LEGENDARYMEMBER"
legend.Parent = Folder
local thebest = Instance.new("BoolValue")
legend.Name = "THEBEST"
legend.Parent = Folder
local valuedmember = Instance.new("BoolValue")
legend.Name = "VALUEDMEMBER"
legend.Parent = Folder
local champion = Instance.new("BoolValue")
legend.Name = "CHAMPION"
legend.Parent = Folder
local data
local success, err = pcall(function()
data = dataStore:GetAsync(player.UserId)
end)
if success and data then
fan.Value = data[1]
diamondmember.Value = data[2]
elitemember.Value = data[3]
goldenmember.Value = data[4]
heroicmember.Value = data[5]
legend.Value = data[6]
legendarymember.Value = data[7]
thebest.Value = data[8]
valuedmember.Value = data[9]
champion.Value = data[10]
else
print("The player has no data!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, err = pcall(function()
saveData(player)
end)
if success then
print("Data has been saved")
else
print("Data has not been saved!")
end
end)
game:BindToClose(function() -- When the server shuts down
for _, player in pairs(game.Players:GetPlayers()) do
local success, err = pcall(function()
saveData(player)
end)
if success then
print("Data has been saved")
else
print("Data has not been saved!")
end
end
end)
The first error that I saw was that half of the bools don’t even go into the folder.
only these 6 replicate:
And if I enable any of the bools, it doesn’t save.
Help please!