Hi there, so I have been using this Datastore for a while and it just randomly stopped working I have no idea why because it has been working for the past 1-2 months but now it just stopped.
If you have any ideas on how I can fix it or why it broke please let me know as fast as you can this is for my game that I need to update today.
I did hide my key’s and datastore name these aren’t the real ones
Thank you
local DataStore = game:GetService("DataStoreService"):GetDataStore("MyDatastore")
local Market = game:GetService("MarketplaceService")
--
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
if not player:FindFirstChild("leaderstats") then
--- leaderstats
local leaderstats = Instance.new("Folder",player)
local Rings = Instance.new("NumberValue",leaderstats)
local Yuans = Instance.new("NumberValue",leaderstats)
local CompletedQuest = Instance.new("BoolValue",player)
CompletedQuest.Name = "CompletedQuest"
Rings.Name = "Rings"
Yuans.Name = "Yuans"
leaderstats.Name = "leaderstats"
--- Datastore
local data
local YuansData
local GliderData
local QuestData
local folder = character:WaitForChild("OwnedGliders")
--local folder = player.Character:WaitForChild("OwnedGliders")
local success,errormessage = pcall(function()
data = DataStore:GetAsync(player.UserId.."MyKey1")
YuansData = DataStore:GetAsync(player.UserId.."MyKey2")
QuestData = DataStore:GetAsync(player.UserId.."MyKey3")
GliderData = DataStore:GetAsync(player.UserId.."Mykey4")
end)
if success then
Rings.Value = data
Yuans.Value = YuansData
CompletedQuest.Value = QuestData
for i,Glider in pairs(GliderData) do
local NewValue = Instance.new("StringValue",folder)
NewValue.Name = Glider
NewValue.Value = Glider
end
else
warn("DataError: "..errormessage.." - "..player.Name)
end
while true do
wait(math.random(120,200))
if player.MembershipType == Enum.MembershipType.Premium then
player.leaderstats.Yuans.Value += math.random(5,10)
end
if Market:UserOwnsGamePassAsync(player.UserId,11855328) then
player.leaderstats.Yuans.Value += math.random(7,15) * 2
else
player.leaderstats.Yuans.Value += math.random(10,20)
end
end
end
end)
end)
----
game.Players.PlayerRemoving:Connect(function(player)
local folder = player.Character:FindFirstChild("OwnedGliders")
local GliderData = {}
for i,Glider in pairs(folder:GetChildren()) do
GliderData[i] = Glider.Value
end
local success,errormessage = pcall(function()
DataStore:SetAsync(player.UserId.."MyKey1",player.leaderstats.Rings.Value)
DataStore:SetAsync(player.UserId.."MyKey2",player.leaderstats.Yuans.Value)
DataStore:SetAsync(player.UserId.."MyKey3",player.CompletedQuest.Value)
DataStore:SetAsync(player.UserId.."MyKey4",GliderData)
end)
if success then
print("saved data".." - "..player.Name)
else
warn("failed to save data: "..errormessage.." - "..player.Name)
end
end)
I would recommend adding some checks on whether the data is there or not like this:
if success then
if data then
Rings.Value = data
end
if YuansData then
Yuans.Value = YuansData
end
if QuestData then
CompletedQuest.Value = QuestData
end
if GliderData then
for i,Glider in pairs(GliderData) do
local NewValue = Instance.new("StringValue",folder)
NewValue.Name = Glider
NewValue.Value = Glider
end
end
else
warn("DataError: "..errormessage.." - "..player.Name)
end
ok I tried that out I reset my data using the Datastore editor plugin and well the only thing is changed is now my data is 0 but even if it did work what about all the others people that play the game? I would need to reset there data.?
I’m pretty sure that’s a bit excessive and you really don’t need to hide your key, reason being is that you can only access your datastore through your game. It is not like a key being used for an external datastore
try doing
data = DataStore:GetAsync(player.UserId.."MyKey1") or 0
add the or 0 to all of them
If that doesn’t work, then potentially you may be getting an infinite yield somewhere, maybe herelocal folder = character:WaitForChild("OwnedGliders")
Not sure if you can store a indexable array in a datastore, so try json encode for GliderData
Other than that, I would player.CharacterAdded and its respective end, because that’s excessive.
yes ik I didn’t need to hide the keys but I did cuz why not lol and doing “or 0” will mainly help if the value is nil so I added if statements to check if there is a value there before actually changing the value and if the WaitForChild was causing an infinite yield it would print that in the output right?